Group - 3 - Practical 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Q1) Write program in C to accept any 2 numbers from

users & calculate their sum & difference.

Q2) Write a program to display square & cube of any


number.
Input:
{
int n;
printf("Enter a number");
scanf("%d",&n);
printf("\nSquare of the number %d is
%d",n,n*n);
printf("\nCube of the number %d is
%d",n,n*n*n);
return 0;
}

Output:
Square of the number 6 is 36
Cube of the number 6 is 216
Q3) Write program in C to accept any 3 numbers from
user & calculate their average.
Input:
#include <stdio.h>
#include<conio.h>
void main()
{
int n1,n2,n3;
float avg;
printf("\nEnter Three Numbers:");
scanf("%d %d %d",&n1,&n2,&n3);
avg=(n1+n2+n3)/3;
printf("\nAverage: %0.2f",avg);
getch();

}
Output:
Enter Three Numbers:30
40
50
Average:40.00
Q4) Write program in C to accept principal amount ,
No of years , Rate of interest from user &
calculate Simple Interest.
Input
Input:-
#include<stdio.h>
int main()
{
float P,R,T,SI;
P=34000;
R=30;
T=5;
SI=(P*R*T)/100;
printf("\n\n Simple Interest os:%f",SI);
return(0);
}
Output:

Output:-Simple Interest os:51000.000000

Q5) Write program in C to calculate area &


perimeter of a circle.
Input:
#include<stdio.h>
#include<conio.h>
void main()
{
float rad, area, per;
clrscr();
printf(“\n\t Enter Radius Of Circle:”);
scanf(“%f”,&rad);
area= 3.14*rad*rad;
per= 2*3.14*rad;
printf(“\n\t Area Of Circle= %.2f”, area);
printf(“\n\t Perimeter Of Circle= %.2f”, per);
getch();
}

Output:
Enter Radius Of Circle:2
Area Of Circle= 12.56
Perimeter Of Circle= 12.56

Q6)

Write program in C to swap any 2 numbers using 3 rd


variable.

Input:
#include<conio.h>
#include<stdio.h>
void main()
{
int a, b, temp;
printf("\n\t Enter a : ");
scanf("%d", &a);
printf("\n\t Enter b : ");
scanf("%d", &b);
printf("\n\n\t Before Swap : a = %d \t b = %d", a,
b);
temp = a;
a = b;
b = temp;
printf("\n\n\n\t After Swap : a = %d \t b = %d", a,
b);
getch();
}

Output:
Enter a : 34
Enter b : 35
Before Swap : a = 34 b = 35
After Swap : a = 35 b = 34

Q7) Write program in C to swap any 2 numbers


without using 3rd variable.
Input:#include<stdio.h>
int main()
{
int a=10,b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n After swap a=%d b=%d",a,b);
return(0);
}
Output:

Output:-Before swap a=10 b=20


After swap a=20 b=10

Q8) Write program in C to swap any 3 numbers using


4th variable.
#include<stdio.h>
int main()
{
int x,y,z,temp;
printf("enter value of x,y,z: ");
scanf("%d,%d,%d",&x,&y,&z);
printf("value before swap are\n x = %d\n z = %d\
n",x,y,z);
temp = x;
x = y;
y = z;
z = temp;
printf("Value after swap are\n x = %d\n y = %d\n z
= %d\n",x,y,z);
return 0;
}
Output:
enter value of x,y,z: 3,4,5
value before swap are
x = 3
y = 4
z = 5
value after swap are
x = 4
y = 5
z = 3

Q9) Write program in C to swap any 3 numbers


without using 4th variable.

Q10) Write program in C to accept marks of any 5


subject & calculate total marks & percentage.
Input: #include <stdio.h>
int main()
{
float eng, phy, chem, math, comp;
float total, percentage;

printf("Enter marks of five subjects: \n");


scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);
total = eng + phy + chem + math + comp;
percentage = (total / 500.0) * 100;

printf("Total marks = %.2f\n", total);


printf("Percentage = %.2f", percentage);

return 0;
}
Output:-
Enter marks of five subjects:
90
87
76
73
82
Total marks = 408.00
Percentage = 81.60

Q11) Write program in C to calculate total amount


of purchase by accepting price & quantity of
notebooks.

You might also like