The document contains 11 questions asking to write C programs to perform various calculations. These include: calculating the sum and difference of two numbers; displaying the square and cube of a number; calculating the average of three numbers; calculating simple interest; calculating the area and perimeter of a circle; swapping two and three numbers with and without a third/fourth variable; and calculating total marks and percentage based on marks from five subjects. For each question, the input C code and expected output is provided.
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 ratings0% found this document useful (0 votes)
27 views11 pages
C - Practical - 3 - Group - 3
The document contains 11 questions asking to write C programs to perform various calculations. These include: calculating the sum and difference of two numbers; displaying the square and cube of a number; calculating the average of three numbers; calculating simple interest; calculating the area and perimeter of a circle; swapping two and three numbers with and without a third/fourth variable; and calculating total marks and percentage based on marks from five subjects. For each question, the input C code and expected output is provided.
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/ 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);
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(); }