0% found this document useful (0 votes)
14 views24 pages

sandhiya

The document contains multiple C programs demonstrating various programming concepts such as calculating the area and circumference of a circle, swapping two numbers, converting Fahrenheit to Celsius, finding the largest of three numbers, and checking voting eligibility. It also includes programs for basic arithmetic operations, summing odd numbers, printing number series, and handling arrays and strings. Each program is accompanied by sample outputs to illustrate functionality.

Uploaded by

Mohanapriya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views24 pages

sandhiya

The document contains multiple C programs demonstrating various programming concepts such as calculating the area and circumference of a circle, swapping two numbers, converting Fahrenheit to Celsius, finding the largest of three numbers, and checking voting eligibility. It also includes programs for basic arithmetic operations, summing odd numbers, printing number series, and handling arrays and strings. Each program is accompanied by sample outputs to illustrate functionality.

Uploaded by

Mohanapriya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

PROGRAM: (AREA AND CIRCUMFERENCE OF THE CIRCLE)

#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

The first number is 75


The second number is 50
PROGRAM (CONVERT FAHRENHEIT INTO DEGREE CELSIUS)

#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");

printf("Enter your age:");


scanf("%d", &age);
if(age>=18)
goto yes; //goto label g
else
goto no; //goto label s
}

Output:-1

Enter your age: 32


You are Eligible

Output:-2

Enter your age: 22


You are not Eligible
PROGRAM:

#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

Enter Your Choice : 1


Enter the 2 nos a and b:2 8
Addition : 10.

Enter Your Choice : 2

Enter the 2 nos a and b: 5 2


Subtraction : 3.

Enter Your Choice : 3


Enter the 2 nos a and b: 2 8
Multiplication : 16.

Enter Your Choice : 4.


Enter the 2 nos a and b: 8 4
Division : 2.

Enter Your Choice : 0.


Exit.
PROGRAM: (Taking input from the user until entering zero)

#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:

Enter the number:2


Enter the number:3
Enter the number:4
Enter the number:5
Enter the number:0
Bye
PROGRAM: (Sum of odd numbers upto 10)

#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:

Enter the limit 10


1
2
3
4
5
6
7
8
9
10
PROGRAM (To Print the sum of number series up to the given limit n)

#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

Enter the limit 10

Sum of series upto 5 is 15

Output: - 2

Enter the limit 10

Sum of series upto 5 is 55


PROGRAM (To Print the even numbers up to the given limit n)

#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

Enter the limit 15


2
4
6
8
10
12
14
PROGRAM (To Print sum of given array elements up to the given limit n)

#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

Sum of the given array numbers is 150


PROGRAM (FOR MATRIX ADDITION)

#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:

Enter the rows and column of two matrix: 3 3

Enter the elements of A matrix: 1 2 3 4 5 6 7 8 9


Enter the elements of B matrix: 1 2 3 4 5 6 7 8 9
The elements of A matrix
123
456
789

The elements of B matrix


123
456
789

The addition of two matrices


246
8 10 12
14 16 18
PROGRAM ( FOR MULTI DIMENSIONAL ARRAY)

#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:

Enter the string: vimalraj

Length of the given string vimalraj is 8


PROGRAM

#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:

Enter the string: vimal


Copied New String is vimal
PROGRAM

#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:

Enter the string1: Vimalraj


Enter the string2: Raja
Copied New String is VimalrajRaja
PROGRAM

#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:

Enter the string: vimalraj

Reverse of the given string is jarlamiv


PROGRAM

#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:

Enter how many elements: 8


Enter the elements: 50
20
60
30
10
80
90
70

Enter the element to search: 30


Element 30 is found in the position 4

OUTPUT-2:

Enter how many elements: 8


Enter the elements: 50
20
60
30
10
80
90
70

Enter the element to search: 100


The element is not found

You might also like