#include<conio.h>
void main()
{
int i, count=0;
clrscr();
for(i=1;i<=10;i++){
if(i>4)
{
++count;
}
}
printf("
Total number grater then 4 are: %d",count);
getch();
}
(b). Write a program in C that prompts the user with the following lines:
a) Add two integers
c) Compare two integers for the larger
t) Test an integer for odd or even
q) Quit
Solution: #include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum,ch;
char another='y';
clrscr();
while(another=='y'){
printf("
You have four choice:
");
printf("1: Add two integers.
");
printf("2: Compare two integers for the larger.
");
printf("3: Test the integer for odd or even.
");
printf("4: Quit
");
printf("Enter Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("
Enter two value :");
scanf("
%d%d",&a,&b);
sum=a+b;
printf("
Add two integer is :%d",sum);
break;
case 2:
printf("
Enter two number :");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("
The grater number is %d.",a);
}else{
printf("
The grater number is %d.",b);
}
break;
case 3:
printf("
Enter any number :");
scanf("%d",&a);
if(a%2==0)
{
printf("
The number is even.");
}else{
printf("
The number is odd.");
}
break;
case 4:
exit();
break;
default:
printf("
You have entered wrong.");
}
printf("
For continue enter y:");
another=getch();
}
}
(c). Write a function celsius() to convert degrees Fahrenheit to degrees Celsius.
Note: The conversion formula is °C = 5/9 * (°F - 32) (5×3=15 Marks)
Solution:
#Inclide<stdio.h>
#inclide<conio.h>
main()
{
float C; F;
printf(“Enter the tem. in Fahrenheit:”);
scnsf(“%f”,&F );
C=Float 5/9*(F-32);
printf(“
Tem. In Celsius:”);
}
Assignment Index | <<Previous Answer | Next Answer>>