sandhiya
sandhiya
#include<stdio.h>
#include<conio.h>
void main()
{
float r,area,circum;
clrscr();
printf("\n Enter the radius of the Circle");
scanf("%f",&r);
area=3.14*r*r;
circum=2*3.14*r;
printf("\n Area=%f",area);
printf("\n Circumference=%f",circum);
getch();
}
Output:
Enter the radius of the Circle 5
Area = 78.500000
Circumference = 31.400000
PROGRAM (SWAP TWO NUMBERS WITHOUT USING TEMPORARY
VARIABLE)
#include<stdio.h>
#include<conio.h>
void main()\
{
int num1,num2;
clrscr();
printf(“\n Enter the first number:”)
scanf(“%d”,&num1);
printf(“\n Enter the second number:”)
scanf(“%d”,&num2);
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
printf(“\n The first number is %d”,num1);
printf(“\n The second number is %d”,num2);
}
Output:
Enter the first number: 50
Enter the Second number: 75
#include<stdio.h>
#include<conio.h>
void main()\
{
float fahrenheit,celsius;
clrscr();
printf(“\n Enter the temperature in Fahrenheit: “)
scanf(“%f”,&fahrenheit);
celsius=(0.56)*(Fahrenheit-32);
printf(“\n Temperature in Degree Celsius is %f “,celsius);
getch();
}
Output:
Enter the temperature in Fahrenheit: 32
Temperature in Degree Celsius is 0
PROGRAM (LARGEST OF THREE NUMBERS)
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter the values of A,B and C: ");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c) {
printf("A is Greater than B and C");
}
else if (b > a && b > c) {
printf("B is Greater than A and C");
}
else if (c > a && c > b) {
printf("C is Greater than A and B");
}
else {
printf("all are equal or any two values are equal");
}
return 0;
}
Output:
Enter the values of A,B and C: 3 5 8
C is Greater than A and B
PROGRAM: (FINDING THE ELIGIBILITY FOR VOTING)
#include<stdio.h>
void main()
{
int age;
yes: //label name
printf("you are Eligible\n");
no: //label name
printf("you are not Eligible");
Output:-1
Output:-2
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, n;
clrscr();
printf(“1. Addition\n”);
printf(“2. Subtraction\n”);
printf(“3. Multiplication\n”);
printf(“4. Division\n”);
printf(“0. Exit\n”);
printf(“Enter your choice : “);
scanf(“%d”,&n);
printf(“Enter the two numbers :”);
scanf(“%d,%d”,&a,&b);
switch(n)
{
case 1:
c = a + b;
printf(“Addition :%d\n”,c);
break;
case 2:
c = a – b;
printf(“Subtraction :%d\n”,c);
break;
case 3:
c = a * b;
printf(“Multiplication :%d\n”,c);
break;
case 4:
c = a / b;
printf(“Division :%d\n”,c);
break;
case 0:
exit(0);
break;
}
getch();
}
OUTPUT:
1. Addition
2. Subtraction
3. Multiplication
4. Division
0. Exit
#include <stdio.h>
int main ()
{
int a;
while (1)
{
printf("Enter the number:");
scanf("%d", &a);
if ( a == 0 )
printf(“Bye”);
break;
}
return 0;
}
Output:
#include <stdio.h>
int main ()
{
int a,sum = 0;
for (a = 0; a < 10; a++)
{
if ( a % 2 == 0 )
continue;
sum = sum + a;
}
printf("Sum = %d",sum);
return 0;
}
Output:
Sum = 25
PROGRAM (To Print the number series up to the given limit n)
#include <stdio.h>
int main()
{
int i, n;
printf(“Enter the limit:”);
scanf(“%d”,&n);
for (i=1; i<=n; i++)
{
printf("%d\n", i);
}
return 0;
}
Output:
#include <stdio.h>
int main()
{
int i=0, n, sum=0;
printf(“Enter the limit:”);
scanf(“%d”,&n);
while (i<=n)
{
Sum = sum + i;
i= i + 1;
}
printf(“Sum of series upto %d is %d”,n,sum);
return 0;
}
Output: - 1
Output: - 2
#include <stdio.h>
int main()
{
int i=0, n, sum=0;
printf(“Enter the limit:”);
scanf(“%d”,&n);
do
{
i= i + 2;
print( i );
}(while i<=n)
printf(“Sum of series upto %d is %d”,n,sum);
return 0;
}
Output: - 1
#include <stdio.h>
int main()
{
int a[5]; i=0, n, sum=0;
printf(“Enter the limit:”);
scanf(“%d”,&n);
for (i=0;i<=n;i++)
{
printf(“Enter the number: ”);
scanf(“%d”,&a[i]);
sum = sum + a[i];
i = i + 1;
}
printf(“Sum of the given array numbers is %d”,sum);
return 0;
}
Output: - 1
Enter the limit 5
Enter the number: 10
Enter the number: 20
Enter the number: 30
Enter the number: 40
Enter the number: 50
#include<stdio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],i,j,m,n;
clrscr();
printf("Enter the rows and column of two matrix:\n");
scanf("%d%d",&m,&n);
printf("\n Enter the elements of A matrix:”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("\nEnter the elements of B matrix:");
for(i=0;i<m;i++)
{
for( j=0;j<n;j++)
scanf("%d",&b[i][j]);
}
printf("\nThe elements of A matrix");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
}
printf("\nThe elements of B matrix");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",b[i][j]);
}
printf("\nThe addition of two matrices");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("\t%d",c[i][j]);
}
}
getch();
}
OUTPUT:
#include<stdio.h>
int main()
{
int tables, rows, columns;
int Employees[2][2][3] = { { {9, 99, 999}, {8, 88, 888} },
{ {225, 445, 665}, {333, 555, 777} }
};
for (tables = 0; tables < 2; tables++)
{
for (rows = 0; rows < 2; rows++)
{
for (columns =0; columns < 3; columns++)
{
printf("Employees[%d][%d][%d] = %d\n", tables, rows, columns,
Employees[tables][rows][columns]);
}
}
}
return 0;
}
OUTPUT:
Employees [0][0][0] = 9
Employees [0][0][1] = 99
Employees [0][0][2] = 999
Employees [0][1][0] = 8
Employees [0][1][1] = 88
Employees [0][1][2] = 888
Employees [0][2][0] = 225
Employees [0][2][1] = 445
Employees [0][2][2] = 665
Employees [0][0][0] = 333
Employees [0][0][0] = 555
Employees [0][0][0] = 777
PROGRAM ( TRAVERSING ONE DIMENSIONAL ARRAY)
#include <stdio.h>
int main()
{
int a[6]={10,20,30,40,50,60};
int i;
for (i=0; i<6; i++)
{
printf(“Element in position[%d] is %d”,i+1,a[i]);
}
}
OUTPUT:
Element in position[1] is 10
Element in position[2] is 20
Element in position[3] is 30
Element in position[4] is 40
Element in position[5] is 50
Element in position[6] is 60
PROGRAM:
#include<stdio.h>
void main()
{
char str1[20];
int len;
printf("Enter the string: ");
scanf("%s",&str1);
len=strlen(str1);
printf("Length of the given string %s is %d",str1,len);
}
OUTPUT:
#include<stdio.h>
void main()
{
char str1[20],str2[20];
int len;
printf("Enter the string");
scanf("%s",&str1);
strcpy(str2,str1);
printf("Copied New String is %s",str2);
}
OUTPUT:
#include<stdio.h>
void main()
{
char str1[20],str2[20];
int len;
printf("Enter the string1: ");
scanf("%s",&str1);
printf("Enter the string2: ");
scanf("%s",&str2);
strcat(str1,str2);
printf("Copied New String is %s",str1);
}
OUTPUT:
#include<stdio.h>
void main()
{
char str1[20],str2[20];
int comp;
printf("Enter the string1: ");
scanf("%s",&str1);
printf("Enter the string2: ");
scanf("%s",&str2);
comp=strcmp(str1,str2);
if (comp==0)
{
printf("Two strings are same");
}
else
{
printf("Two strings are not same");
}
}
OUTPUT:-1
Enter the string1: Vimal
Enter the string2: Vimal
Two strings are same
OUTPUT:-2
Enter the string1: Vimal
Enter the string2: Kamal
Two strings are not same
PROGRAM
#include<stdio.h>
void main()
{
char str1[20],rec[20];
printf("Enter the string: ");
scanf("%s",&str1);
printf("Reverse of the given string is %s”,strrev(str));
}
OUTPUT:
#include<stdio.h>
void linear(int [ ], int, int);
main()
{
int i, n, x, a[20];
printf(“Enter how many elements:”);
scanf(“%d”,&n);
printf(“\n Enter the elements”);
for ( i=0; i<n; i++)
{
scanf(“%d\n”,&a[i]);
}
printf(“\n Enter the element to search:”);
scanf(“%d”,&x);
linear(a.n,x);
// Function call
}
void linear(int a[ ], int n, int x)
{
int i, flag=0;
for(i=0; i<n; i++)
{
if ( x == a[i])
{
flag = 1;
break;
}
}
if (flag = = 1)
{
printf(“\n Element %d is found in the position %d”,a[i], i+1);
else
printf(“\n The element is not found in the list”);
}
OUTPUT-1:
OUTPUT-2: