0% found this document useful (0 votes)
35 views7 pages

CP Practical 2

Ch

Uploaded by

kirtan.br.007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views7 pages

CP Practical 2

Ch

Uploaded by

kirtan.br.007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Date : 20/08/2024

Roll No. and Name : 24ITA014 , Kalola Tej Hiteshbhai

Course Code and Name : 1CS501 , Computer Programming

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!");
}

printf("\nAdditon of a and b is:%d \n", Add);


printf("Substract of a and b is:%d \n", Substract);
printf("Multiply of a and b is:%d \n", Multiply);
printf("Division of a and b is:%d \n", Division);
printf("Modules of a and b is:%d \n", Modules);

return 0;
}
Input/output :

Practical No : 2(b)

AIM : Calculate the net payment to any employee

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;

printf("New value of a: %d",a);


printf("\n New value of b: %d",b);

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)

AIM : To find the greatest of two using the ternary operator.

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);

MAX = (n1>n2)? n1:n2;


printf("Maximum value is %d",MAX);

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…

You might also like