You are on page 1of 6

1.

Write a C program to prompt the user to input 3 integer values and print these
values.
INPUT:

int main()
{
int a,b,c;
printf("enter the three numbers:\n");
scanf("%d %d %d",&a,&b,&c);
printf("The numbers are=\n%d\n%d\n%d\n",a,b,c);
}

OUTPUT:
enter the three numbers:
1
2
3
The numbers are=
1
2
3
2. Write a C program to determine biggest among two numbers using Conditional
operator
INPUT:
#include<stdio.h>
int main()
{
int a,b;
printf("enter 2 num:\n");
scanf("%d %d",&a,&b);
if(a>b)
{
printf("a is biggest");
}

else
{
printf("b is biggest");

}
}

OUTPUT:
enter 2 num:
2
3
b is biggest
3. Write a C program to calculate area and circumference of a circle.
INPUT:
#include<stdio.h>
#define PI 3.14
int main()
{
int r;
double area,cir;
printf("enter radius:");
scanf("%d",&r);
area=PI*(r*r);
cir=2*PI*r;
printf("area=%f",area);
printf("circumference=%f",cir);

OUTPUT:
enter radius:5
area=78.500000circumference=31.400000
4. Write a C program to swap values of two variables with and without using third variable.

INPUT:
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter 2 num:"\n);
scanf("%d %d",&a,&b);
c=a+b;
a=c-a;
b=c-b;
printf("a=%d",a);
printf("b=%d",b);
}
OUTPUT:
enter 2 num:
10
20
a=20b=10
INPUT:
#include<stdio.h>
int main()
{
int a,b;
printf("enter 2 num:");
scanf("%d %d",&a,&b);
a=a-b;
b=a+b;
printf("a=%d",a);
printf("b=%d",b);
}

OUTPUT:
enter 2 num:
20
10
a=10b=20
5. Write a C program to take input of name, rollno and marks obtained by a student in 4
subjects of 100 marks each and display the name, rollno with total and percentage
score secured.
INPUT:
#include<stdio.h>
int main()
{
int regno,rollno,marks1,marks2,marks3,marks4;
float total,percentage;
scanf("%d %d %d %d %d
%d",&regno,&rollno,&marks1,&marks2,&marks3,&marks4);
printf("regno=%d\n",regno);
printf("rollno=%d\n",rollno);
printf("marks1=%d\n",marks1);
printf("marks2=%d\n",marks2);
printf("marks3=%d\n",marks3);
printf("marks4=%d\n",marks4);
total=marks1+marks2+marks3+marks4;
percentage=(total/400)*100;
printf("total=%.2f\n",total);
printf("percentage=%.2f",percentage);
}

OUTPUT:
123
52
95
96
97
98
regno=123
rollno=52
marks1=95
marks2=96
marks3=97
marks4=98
total=386.00
percentage=96.50

6. Write a program that calculates mileage reimbursement for a salesperson at a rate of


$.35 per mile. Your program should interact with the user in this manner:
MILEAGE REIMBURSEMENT CALCULATOR
Enter beginning odometer reading=> 13505.2
Enter ending odometer reading=> 13810.6
You traveled 305.4 miles. At $0.35 per mile,
your reimbursement is $106.89.
INPUT:
#include<stdio.h>
int main()
{
float bor,eor,reimbursement,trav,rate=0.35;
scanf("%f %f",&bor,&eor);
printf("beginning odometer reading=%f\n",bor);
printf("ending odometer reading=%f\n",eor);
trav=eor-bor;
reimbursement=trav*rate;
printf("reimbursement=%f\n",reimbursement);

}
OUTPUT:
#include<stdio.h>
int main()
{
float bor,eor,reimbursement,trav,rate=0.35;
scanf("%f %f",&bor,&eor);
printf("beginning odometer reading=%f\n",bor);
printf("ending odometer reading=%f\n",eor);
trav=eor-bor;
reimbursement=trav*rate;
printf("reimbursement=%f\n",reimbursement);

You might also like