Professional Documents
Culture Documents
22CLK038 LPW2-1
22CLK038 LPW2-1
22CLK038 LPW2-1
Computer Programming
Roll no.: 22CLK038
Name: DEV PATEL
(a). Scan two numbers and display result of different arithmetic operations
(+, - , *, / and %).
• Code
#include <stdio.h>
int main()
int a,b,sum,diff,pro,divi,mod;
scanf("%d",&a);
scanf("%d",&b);
sum=a+b;
diff=a-b;
pro=a*b;
divi=a/b;
mod=a%b;
printf("\nthe sum of %d and %d is %d",a,b,sum);
return 0;
• Run Program
(b). The driver is driving a car from city Ahmedabad to city Mumbai, in
Ahmedabad temperature displays in Celsius while in Mumbai the
temperature displayed in Fahrenheit, a driver wants to find the difference
between the temperatures of two cities in Celsius. (Celsius = (F-32) *(5/9))
• Code
#include <stdio.h>
int main()
{
float b,mf,mc,diff;
printf("enter ahmedabad temp in celsius\n");
scanf("%f",&b);
printf("enter mumbai temp in fahrenheit\n");
scanf("%f",&mf);
mc=(5*mf-160)/9;
diff=b-mc;
printf("\ndifference in temp of ahmedabad and mumbai in celsius is
%f",diff);
return 0;
}
• Run Program
•
•
• Code
#include <stdio.h>
int main()
{
float a,da,hra,medical,pf,insu,deduc,gross,net;
printf("enter basic salary\n");
scanf("%f",&a);
da=a*0.5;
hra=a*0.1;
medical=a*0.04;
gross=a+da+hra+medical;
pf=gross*0.05;
insu=gross*0.07;
deduc=insu+pf;
net=gross-deduc;
printf("\n net salary is %f",net);
printf("\n gross salary is %f",gross);
printf("\n total deduction in salary is %f",deduc);
printf("\n pf is %f",pf);
printf("\n da is %f",da);
printf("\n hrais %f",hra);
printf("\n insu is %f",insu);
printf("\n medical is %f",net);
return 0;
}
• Run Program
(e). Read the price of item in decimal form. For example, 12.52 and separate
rupee and paise from the given value. For example, 12 rupees and 52 paise.
• Code
#include <stdio.h>
#include <math.h>
int main()
{float raw;
int rup,pai;
printf("“enter price\n");
scanf("%f",&raw);
rup= raw;
pai=(raw-rup)*100;
printf("%d””rupees and “”%d””paise", rup,pai);
return 0;
}
• Run program
(f). To swap the value of two numbers (i) using and (ii) without using a
temporary variable.
• Run Program
• Code without using temporary variabl
#include <stdio.h>
int main()
{
int a=10,b=20,temp;
printf("\n before swap a=%d,b=%d ",a,b);
//swap steps using arithmetic operation;
a=a+b;
b=a-b;
a=a-b;
printf("\n after swap a=%d,b=%d",a,b);
return 0:
}
Run Program
(g). To find greatest of two and three numbers using the ternary operator.
• Code
#include <stdio.h>
int main()
{
int a,b,c,g;
printf("enter the value of a");
scanf ("%d",&a);
printf("enter the value of b");
scanf ("%d",&b);
printf("enter the value of c");
scanf ("%d",&c);
g = ("(a>b)?(a>c)?(a>c)(b>c)?(b>c)?");
printf("the value of g is %d",g);
return 0;
}
Run Program