ASHA
ASHA
ASHA
Website: mcmdavcwchd.edu.in
(C Programming)
1
SR.NO PROGRAM NAME PAGE NO. TEACHER’S
SIGNATURE
2 Reverse of a number 5
8 Factorial of a number 11
2
17 Salary of employee using if else if ladder 21
20 Conditional operator 24
3
CODE:
#include<conio.h>
#include<stdio.h>
int main()
{ int a,b;
long x,y;
float f=64.64567890;
double g=11.0123456789;
char ch;
unsigned char u;
ch= '+';
u= 'A';
scanf("\n%d%d%ld%ld",&a,&b,&x,&y);
printf("\n%d\n%d\n%ld\n%ld",a,b,x,y);
printf("\n%f\n%lf",f,g);
return 0;
OUTPUT:
4
CODE:
#include<conio.h>
#include<stdio.h>
int main()
int rev,rem,num,n;
scanf("%d",&n);
num=n;
while(num!=0)
rem=num%10;
num=num/10;
rev=rev*10+rem;
printf("\nThe number=%d",n);
getch();
OUTPUT:
#include<stdio.h>
int main()
int a,b,max;
max = a>b ? a : b;
return 0;
OUTPUT:
6
CODE:
#define PI 3.14159
#include<stdio.h>
#include<conio.h>
int main()
int R;
float C;
float area,perimeter;
C=PI;
scanf("%d",&R);
perimeter=2.0*R*C;
area=C*R*R;
getch();
OUTPUT:
7
CODE:
#include<stdio.h>
#include<conio.h>
int main()
int x;
x= 27.67;
float y;
y= 55;
char z;
z= 9;
getch();
Output:
8
CODE:
#include<stdio.h>
#include<conio.h>
int main()
inta,b,c;
scanf("%d %d",&a,&b);
c=a;
a=b;
b=c;
getch();
OUTPUT:
9
CODE:
#include<stdio.h>
#include<conio.h>
int main()
scanf("\n %d",&Fahrenheit);
Celsius = ((Fahrenheit-32)*5)/9;
return 0 ;
OUTPUT:
int main()
int i,fact=1,number;
printf("enter a number\n");
scanf("%d",&number);
for(i=1;i<=number;i++)
fact=fact*i;
return 0;
OUTPUT:
#include<conio.h>
int main()
int a,b;
scanf("%d%d",&a,&b);
if (a>b)
else
getch();
OUTPUT:
/*In a company if employee’s basic salary is less than or equal to 10,000. Then
his DA is 31% of basic salary ,HRA is 12% of basic, MA is Rs.250. If his salary is
12
greater than 10,000 then DA is 35% of basic, HRA is 15% of basic & MA is 350.
Calculate his gross salary*/
CODE:
#include<stdio.h>
#include<conio.h>
int main()
{
int basic,da,hra,ma,gross;
printf("enter basic salary of an employee\n");
scanf("%d",&basic);
if(basic<=10000)
{
da=basic*31/100;
hra=basic*12/100;
ma=250;
}
else
{
da=basic*35/100;
hra=basic*15/100;
ma=350;
}
gross=basic+da+hra+ma;
printf("salary of an employee=%d",gross);
getch();}
OUTPUT:
13
#include<stdio.h>
#include<conio.h>
int main()
int num;
scanf("%d",&num);
if(num%2==0)
else
getch();
OUTPUT:
14
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter three numbers\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("biggest no is %d",a);
else
printf("biggest no is %d",c);
}
else
{
if(b>c)
printf("biggest no is %d",b);
else
printf("biggest no is %d",c);
}
getch();
}
OUTPUT:
15
#include<stdio.h>
#include<conio.h>
int main()
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
if((b>a)&&(b>c))
if((c>a)&&(c>b))
getch();
OUTPUT:
16
#include<stdio.h>
#include<conio.h>
int main()
{
int day;
printf("enter the day of week as numbers\n");
scanf("%d",&day);
if(day==1)
printf("Day is Monday");
else if(day==2)
printf("Day is Tuesday");
else if(day==3)
printf("Day is Wednesday");
else if(day==4)
printf("Day is Thursday");
else if(day==5)
printf("Day is Friday");
else if(day==6)
printf("Day is Saturday");
else if(day==7)
printf("Day is Sunday");
else
printf("Wrong input");
getch();
}
OUTPUT:
17
#include <stdio.h>
int main()
{
int choice =0;
printf("MENU:\n1. BURGER\n2. PIZZA\n3. Exit");
while(1){
printf("\nEnter your choice:");
scanf("%d", &choice);
if(choice == 1)
{
printf("> Enjoy your BURGER!\n");
}
else if (choice == 2)
{
printf("> Enjoy your PIZZA!\n");
}
else if (choice == 3)
{
printf("BYE!!!\n");
break;
}
Else
{
printf("> Invalid Input\n");
}
}
return 0;
}
OUTPUT:
18
CODE:
#include<stdio.h>
int main(void)
{
int angle;
printf("enter an angle in degrees:");
scanf("%d",&angle);
angle=angle%360;
if(angle%90==0) printf("angle %d lies on an axis\n",angle);
else
if( angle >0 && angle <90)
{
printf("\nThe angle is in quadrant I");
}
else if( angle >90 && angle <180)
{
printf("\nThe angle is in quadrant II");
}
else if(angle >180 && angle <270)
{
printf("\nThe angle is in quadrant III");
}
else if (angle >270 && angle <360 )
{
printf("\nThe angle is in quadrant IV");
}
if(angle%90==0)
switch(angle/90)
{
case 0:
printf("\nThe angle is on the positive X axis");
break;
case 1:
printf("\nThe angle is on the positive Y axis");
break;
case 2:
printf("\nThe angle is on the negative X axis");
break;
case 3:
printf("\nThe angle is on the negative Y axis");
break;
default:
printf("error");
}
return 0;
19
}
OUTPUT:
if (gender=='m'&&yos>=10&&qual==1)
salary = 15000;
else if ((gender=='m'&&yos>=10&&qual==0)||(gender=='m'&&yos<10&&qual==1))
salary = 10000;
else if (gender=='m'&&yos<10&&qual==0)
salary = 7000;
else if (gender=='f'&&yos>=10&&qual==1)
salary = 12000;
else if (gender=='f'&&yos>=10&&qual==0)
salary = 9000;
else if (gender=='f'&&yos<10&&qual==1)
salary = 10000;
else if (gender=='f'&&yos<10&&qual==0)
salary = 6000;
printf("\nSalary of employee=%d\n",salary);
return 0;
}
OUTPUT:
21
CODE:
#include<stdio.h>
int main()
int i;
for(i=0;i<10;i++)
if (i==3)
break;
printf("%d\n",i);
return 0;
OUTPUT:
CODE:
22
#include<stdio.h>
int main()
int i;
for(i=0;i<10;i++)
if (i==3)
continue;
printf("%d\n",i);
return 0;
OUTPUT:
23
CODE:
#include <stdio.h>
int main()
int num;
scanf("%d", &num);
return 0;
OUTPUT:
CODE:
24
#include<stdio.h>
#include<conio.h>
int main ()
int a[5], i;
scanf("%d", &a[i]);
printf("%d",a[i]);
getch();
OUTPUT:
25
CODE:
#include <stdio.h>
int main()
{
int rows,cols;
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);
int arr[rows][cols];
printf("Enter the elements of the 2D array:\n");
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
printf("Enter element at row %d, column %d: ", i + 1, j + 1);
scanf("%d", &arr[i][j]);
}
}
printf("The 2D array is:\n");
for (int i = 0; i < rows; i++)
{
for (int j=0;j<cols;j++)
{
printf("%d",arr[i][j]);
}
printf("\n");
}
return 0;
}
OUTPUT:
26
#include<stdio.h>
int main()
int array1[10][10],i,j,m,n,sum = 0;
scanf("%d", &m);
scanf("%d",&n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&array1[i][j]);
for(i=0;i<m;++i)
for(j=0;j<n;++j)
printf("\t%d",array1[i][j]);
printf("\n");
27
}
return 0;
OUTPUT:
/*Program to read A list of 10 numbers and print the list in reverse order*/
CODE:
28
#include<stdio.h>
int main()
{
int S[10];
int i;
printf("Enter the list of 10 numbers:\n");
for (i=0;i<number;i++)
{
scanf("%d", &S[i]);
}
printf("\nThe reverse order of given list is:");
for ( i=9;i>=0;i--)
{
printf("\n%d",S[i]);
}
return 0;
}
OUTPUT:
CODE:
29
#include<stdio.h>
int main()
int calsum(int,int);
return 0;
int num3;
return (num3);
OUTPUT:
CODE:
30
#include <stdio.h>
int main()
int res;
return res;
OUTPUT:
CODE:
31
#include <stdio.h>
#include<conio.h>
int main()
int x, y;
swap(x, y);
return 0;
int temp;
temp = a;
a = b;
b = temp;
OUTPUT:
CODE:
32
#include <stdio.h>
Int main()
int x, y;
swap(&x, &y);
return 0;
int temp;
temp = *a;
*a = *b;
*b = temp;
OUTPUT:
CODE:
33
#include<stdio.h>
int main()
int i=5;
printf("\naddress of i=%u",&i);
return 0;
OUTPUT:
CODE:
34
#include<stdio.h>
int main()
int i=5,*j;
j=&i;
return 0;
OUTPUT:
CODE:
35
#include<stdio.h>
#include<conio.h>
int main()
{ int show(int);
int m[]={30,40,50,60,70,80},i;
for(i=0;i<6;i++)
show(m[i]);
return 0;
show(int marks)
printf("\t%d",marks);
OUTPUT:
36
37