CP Practical 2
CP Practical 2
Practical No : 2(a)
AIM : Scan two numbers and display result of different arithmetic operations
(+, -, *, / and %).
Methodology followed :
#include <stdio.h>
int main()
{
int a,b,Add,Substract,Multiply,Division,Modules;
printf("Add Two Numbers :");
scanf("%d%d",&a,&b);
Add = a+b;
Substract = a-b;
Multiply = a*b;
Modules = a%b;
if (b!=0)
{
Division = a/b;
}
else
{
printf("\nDivision Is Not Exist!");
}
return 0;
}
Input/output :
Practical No : 2(b)
Methodology followed:
#include <stdio.h>
int main()
{
float Basic , DA , HRA , Medical , PF , Deduction ,GS , Insurance , Net_Salary;
printf("Enter The Value Of Basic: ",Basic);
scanf("%f",&Basic);
DA = 0.5*Basic;
HRA = 0.1*Basic;
Medical =0.04*Basic;
GS = Basic+DA+HRA+Medical;
PF = 0.05*GS;
Insurance = 0.07*GS;
Deduction = Insurance+PF;
Net_Salary = GS-Deduction;
printf("The net payment of any employee: %f",Net_Salary);
return 0;
Input/output :
Practical No : 2(c)
AIM : To swap the value of two numbers (i) using and (ii) without using a temporary
variable.
Methodology followed:
(i) :
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
c = a;
a = b;
b = c;
return 0;
}
Input/output :
(ii) :
Methodology followed:
#include <stdio.h>
int main()
{
int a,b;
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
a = a+b;
b = a-b;
a = a-b;
printf("New value of a: %d",a);
printf("\n New value of b: %d",b);
return 0;
}
Input/output :
Practical No : 2(d)
Methodology followed:
#include <stdio.h>
int main()
{
int n1,n2,MAX;
printf("Enter the value of number 1:");
scanf("%d",&n1);
printf("Enter the value of number 2:");
scanf("%d",&n2);
return 0;
}
Input/output :
Conclusion : By performing the above practicals , I understood how basic
computational functionalities work and learned about fundamental to developing
efficient and functional code…