C - Practical - 3 - Group - 3

You might also like

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

Practical 3

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


users & calculate their sum & difference.
Input:
#include<stdio.h>
#include<conio.h>
int main;
{
int num1,num2;
int Sum,diff;
clrscr();
printf(“\n Input any two numbers:”);
scanf(“%d,%d”,&num1,&num2);
Sum=num1+num2;
diff=num1-num2;
printf(“\n\t The sum of given numbers=%d”,Sum);
printf(“\n\t The difference of given numbere=%d”,diff);
getch();
}
Output:
Q2) Write a program to display square & cube of any
number.
Input:
#include<stdio.h>
#include<conio.h>
{
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;
getch();
}
Output:
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);
return(0);
}
Output:

Q4) Write program in C to accept principal amount ,


No of years , Rate of interest from user &
calculate Simple Interest.
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:

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

Q6) Write program in


C to swap any 2
numbers using 3rd
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:

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:

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

Q9) Write program in C to swap any 3 numbers


without using 4th variable.
Input:
#include<stdio.h>
void main()
{
int a,b,c;
printf(“\n\t Enter values of a,b and c”)
scanf(“%d %d %d”,&a,&b,&c);

printf(“\n a=%d”,a);
printf(“\n b=%d”,b);
printf(“\n c=%d”,c);
a=a+b+c;
b=a-b-c;
c=a-b-c;
a=a-b-c;

printf(“\n After Swapping their values are as below”);


printf(“\n a=%d”,a);
printf(“\n b=%d”,b);
printf(“\n c=%d”,c);
getch();
}
Output:

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:

Q11) Write program in C to calculate total amount


of purchase by accepting price & quantity of
notebooks.
Input:
#include<stdio.h>
#include<conio.h>
int main()
{
int pri,qua,tot_pri;
printf("\n\t Enter Price of One Notebook:");
scanf("%d",&pri);
printf("\n\t Enter Quantity of Notebooks:");
scanf("%d",&qua);
tot_pri=pri*qua;
printf("\n\t Total Amount Of Purchase=%d",tot_pri);
getch();
}

Output:

You might also like