You are on page 1of 13

1. Amjad basic salary is input through keyboard.

His dearness allowance is 40% of

the basic salary, and house rent allowance is 20% of basic salary. Write a
program to calculate his gross salary.

#include<stdio.h>
#include<conio.h>
void main()
{
int basic_salary;
float dearness_allowance, house_allowance,gross_salary;
clrscr();
printf("Enter basic salary:");
scanf("%d",&basic_salary);
dearness_allowance = (basic_salary*40)/100;
house_allowance = (basic_salary*20)/100;
gross_salary = basic_salary + dearness_allowance + house_allowance;
printf("\nThe Gross salary =%f",gross_salary);
getch();
}

2. Two numbers are input through keyboard in two location C and D. Write a
program to interchange the contents of C and D.

#include<stdio.h>
#include<conio.h>
void main()
{
int c,d,temp;
//c = 0;
//d = 0;
clrscr();
printf("Enter value for c:");
scanf("%d",&c);
printf("\n Enter value for d:");
scanf("%d",&d);
temp = c;
c = d;
d = temp;
printf("\nThe value of C now is: %d",c);
printf("\n The value of D now is: %d",d);
getch();
}
3. The radius of a circle is input through the keyboard. Write a program to
calculate the area & circumference of the circle.
#include<stdio.h>
#include<conio.h>
void main()
{
const float pi = 3.14;
float r,area,circumference;
clrscr();
scanf("%f",&r);
area = pi*r*r;
circumference = 2*pi*r;
printf("\nThe area of the Circle =%.2f",area);
printf("\nThe Circumference =%.2f",circumference);
getch();
}

4. Temperature of a city in centigrade degree is input through the keyboard. Write

a program to convert this temperature into fahrenheit degree

. #include<conio.h>
#include<stdio.h>
void main()
{
float tf,tc;
clrscr();
printf("Enter the value of temp in centigrade:");
scanf("%f",&tc);
tf = (9.0/5)*tc+32;
printf("The temp in fahrenheit =%f",tf);
getch();
}
5. An integer value is entering through keyboard. Write programs that display its
octal equivalent.

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf("\nEnter any decimal value:");
scanf("%d",&x);
printf("\nThe Octal value is %o",x);
getch();
}

6. The length (L) and width (W) of rectangle are input through keyboard. Write a
program to calculate the area and perimeter of the rectangle.
[Hints: Area_of_rectngle = lw, Perimeter_of_rectangle = 2L + 2W
#inclue<stdio.h>
#include<conio.h>
void main()
{
int l,w;
clrscr();
printf("\Enter the the lenght of rectangle:");
scanf("%d",&l);
printf("\n Enter the width of rectangle:");
scanf("%d",&w);
area = l*w;
perimeter = 2*l*w;
printf("\n The area of rectangle =%d",area);
printf("\n The perimeter of rectangle = %d",perimeter);
getch();
}
7. Temperature of a city in Fahrenheit degree is input through the keyboard. Write a
program to convert this temperature into centigrade degree.
[Hints: temp_in_centi = (5.0/9)*(temp_in_fahren – 32)]
#include<stdio.h>
#include<conio.h>
void main()
{
float tc,tf; // tc mean temp in centigarde, tf mean temp in fahrenheit
clrscr();
printf("\n Enter temp in fahrenheit");
scanf("%f",&tf);
tc = ((5.0/9)*(tf-32));
printf("\n The temp in centigrade is %f",tc);
getch();
}

8. If the marks obtained by a student in three different subjects are input through
keyboard, find out the aggregate marks and percentage marks obtained by the
student. Assume that the maximum marks that can be obtained by student in each
subject is 100

#include<stdio.h>
#include<conio.h>
void main()
{
int sub1,sub2,sub3,agr_marks,per;
clrscr();
printf("\nEnter Marks of Subject1:");
scanf("%d",&sub1);
printf("\n Enter marks of Subject2:");
scanf("\n%d",&sub2);
printf("\nEnter Marks of subjects3:");
scanf("%d"&sub3);
agr_mark = sub1 + sub2 + sub3;
per = (agr_mark *100)/300;
printf("\n The Agregate Mark= %d",agr_mark);
printf("\n The Percentage Mark =%d",per);
getch();
}
9. Write a program that calculate the sum and average of three numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z,sum,avg;
clrscr();
printf("\nEnter 3 number:");
scanf("%d%d%d",&x,&y,&z);
sum = x+y+z;
avg = sum/3;
printf("\nThe Sume =%d",sum);
printf("\n The Average=%d",avg);
getch();
}

10. Two numbers are entering through keyboard. Write a program that calculate the
Sum_of_Sqr and Sqr_of_Sum of these numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,sqr_sum,sum_sqr;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&x,&y);
sum_sqr = ((x*x)+(y*y));
sqr_sum = ((x+y)*(x+y));
printf("\nThe Sum of Sqr =%d",sum_sqr);
printf("\n The Sqr of Sum =%d",sqr_sum);
getch();
}

11. If a four-digit number is input through the keyboard. Write a program to calculate
the sum of its digits.
e.g. if number 2345 is enter then the output should be 14(2+3+4+5).

#include<stdio.h>
#include<conio.h>
void main()
{
int num,temp=0,temp1=0;
clrscr();
printf("Enter value for num:");
scanf("%d",&num);
while (num>10)
{
temp = num%10;
temp1 = temp1 + temp;
num = num/10;
}
temp1 = temp1 +num;
printf("The result =%d",temp1);
getch();
}

12. If a four-digit number is input through the keyboard. Write a program to calculate
the sum of first and last digit of this number.
e.g. if number 1234 is enter then the output should be 5 (1+4)

#include<stdio.h>
#include<conio.h>
void main()
{
int num,num1,temp1,temp2,temp3;
clrscr();
printf("Enter number:");
scanf("%d",&num);
temp1 = num % 10;
while (num>10)
{
num1 = num/10;
num = num1;
}
temp2 = temp1 + num;
printf("\n The result =%d",temp2);
getch();
}

13. If four-digit number is input through keyboard. Write a program to reverse the
number.

#include<stdio.h>
#include<conio.h>
void main()
{
int num,temp;
clrscr();
printf("\nEnter number:");
scanf("%d",&num);
while (num>=10)
{
temp = num%10;
num =num/10;
printf("%d",temp);
}
printf("%d",num);
getch();
}

14. Student obtain marks entering through keyboard. If the obtain marks greater than
or equal to 50 then is pass otherwise fail. Write a program to display either
student pass or fail.

void main()
{
int obt_marks;
printf(“Enter marks:”);
scanf(“%d”,&obt_marks);
if(obt_marks>= 50)
printf(“Pass”);
else
printf(“fail”)
}

15. A number is enter through keyboard. Write a program weather number is even or
odd.

void main()
{
int num;
printf(“Enter number:”);
scanf(“%d”,&num);
if(num%2 = = 0)
printf(“The number is Even”);
else
printf(“The number is odd”);
}

16. The current year and the year in which the employee joined the organization are
entered through keyboard. If the number of years for which the employee has served
the organization is greater than 3 then a bonus of Rs.2500/ is given to the employee.
If service is not greater than 3 years then program should display the year of service
not greater than 3 years.

void main()
{
int bonus,current_year,join_year,year_of_ser;
printf(“Enter the year of join :”);
scanf(“%d”, join_year);
printf(“Enter the current year”);
scanf(“%d”,current_year);
year_of_ser = current_year – join_year;
if(year_of_ser >3)
{
bonus = 2500
printf(“The employee bonus =%d”,bonus);
}
else
printf(“ Service of employee is not greater than 3”);
}

16. In company an employee is paid under:

If his basic salary is less than Rs. 1500, than HRA = 10% of basic salary and
DA = 90% of basic salary. If his salary is either equal to or above RS. 1500, then
HRA= Rs. 500 and DA =98% of basic salary. If the employee’s salary is input
through keyboard write a program to find the gross salary.

void main()
{
float basic_sal, gross_sal, da, hra;

printf(“Enter the basic salary:”);

scanf(“%d”,&basic_sal);
if (basic_sal <1500)
{
hra = basic_sal *10/100;
da = basic_sal*90/100;
}
else

{
hra = 500;
da = basic_sal*98/100;
}
gross_sal = basic_sal + hra + da;
printf(“The gross salary =%d”,gross_sal);
}
17. Student marks enter through keyboard. Write a program to display the grade of
student. The grade of student is distributed as :
80 – 100 A
70-79 B
60-69 C
50-59 D
Below 50 Fail

#include<conio.h>
#include<stdio.h>
void main()
{
int obt_mark;
clrscr();
printf("Enter obt_mark:");
scanf("%d",&obt_mark);
if(obt_mark >=80 && obt_mark<=100)
else if (obt_mark >=70 && obt_mark<=79)
else if (obt_mark >=60 && obt_mark <= 69)
else if (obt_mark >=50 && obt_mark <=59)
else if(obt_mark <50)
printf("\n Fail");
else
printf("\nInvalid marks");
getch();
}

18. Write a program for simple calculator i.e. performs the addition, subtraction,
multiplication and division.

#include<stdio.h>
#include<conio.h>
void main()
{
int num1=0,num2=0,result;
char ch;
clrscr();
printf("\n Enter Number1:" );
scanf("%d",&num1);
printf("\n Enter the Operator");
ch = getche();
printf("\n Enter number2:");
scanf("%d",&num2);
switch(ch)
{
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*' :
result = num1 * num2;
break;
case '/' :
if (num2 <=0)
{
printf("\n Num2 must be positive and greater than 0");
break;
}
else
result = num1 / num2;
break;
default :
printf ("\n Invalid Operator");
}
printf("Result of %d %c %d = %d",num1,ch,num2,result);
getch();
}

19. Any character is enter through keyboard, write a program to determine

whether the character is entered is a capital letter, a small case letter, a digit or a
special symbol.
[Hint: use the following table for ASCII values]

Character ASCII Values

A-Z 65-90
a-z 97-122
0-9 48-57
Special symbols 0-47,58-64,91-96,123-127

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\n Enter Character:");
ch = getche();
if(ch>=65 && ch<=90)
printf("\n You have typed Capital Letter");
else if (ch>= 97 && ch<= 122)
printf("\n You have enter small letter");
else if (ch>=48 && ch<=57)
printf("\n You have typed digit");
else
printf("\n You have typed special symbol");
getch();
}

20. Any date (day, month, year) is input through keyboard. Write a program that display
the previous day of that date.(Assume that the year is not leap year)
e.g. the date enter is: 1/5/2006 the output should be: 30/4/2006.

#include<stdio.h>
#include<conio.h>
void main()
{
int dd,mm,yy;
clrscr();
printf("\n Enter any date:");
scanf("%d%d%d",&dd,&mm,&yy);
if((dd==1)&&(mm==2||mm==4||mm==6||mm==8||mm==9||mm==11))

{
dd = 31;
mm = mm -1;
}
else if((dd == 1)&&(mm==3))
{
dd =28;
mm = mm-1;
}
else if((dd==1)&&(mm != 1))

{
dd =30;
mm =mm-1;
}
else if((dd==1)&&(mm ==1))
{
dd =31;
mm =12;
yy = yy-1;
}
else
{
dd = dd-1;
}
printf("\n %d:%d:%d",dd,mm,yy);
getch();
}

21. Any date (day, month, year) is input through keyboard. Write a program that display
the next day of that date.(Assume that the year is not leap year)
e.g. the date enter is: 31/5/2006 the output should be: 1/6/2006.

#include<stdio.h>
#include<conio.h>
void main()
{
int day,mon,yy;
//int f =0;
printf("Enter day,mon,yy");
scanf("%d%d%d",&day,&mon,&yy);
if(day ==30 && (mon==4||mon==6||mon==9||mon==11))
//f = 1;
{
day = 1;
mon = mon +1;
}
else if(day == 28 && mon ==2)
//f =1;
{
day = 1;
mon = mon +1;
}
else if((day == 31)&&(mon!=12))
//f =1;
{
day =1;
mon = mon + 1;
}
else if((day ==31)&&(mon == 12))
{
day = 1;
mon = 1;
yy = yy +1;
}
else
day = day +1;
printf("%d: %d:%d",day,mon,yy);
getch();
}

22. Three numbers are enter through keyboard. Write a program that find the smallest and
largest number.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,min,max;
printf("Enter three values:");
scanf("%d%d%d",&a,&b,&c);
if(a<b && a<c)
min =a;
else if(b<a && b<c)
min =b;
else if (c<a && c<b)
min =c;
if(a>b&&a>c)
max =a;
else if(b>a && b>c)
max = b;
else if(c>a && c>b)
max = c;
printf("\nThe smallest number %d",min);
printf("\n The largest number %d",max);
getch();
}