The document contains the algorithms, flowcharts, and code for 15 programming practical exercises involving calculations of volumes, areas, temperature conversions, exponents, GCD, interest, averages, accelerations, and determining even and prime numbers within ranges. For each practical, it provides the step-by-step algorithm, corresponding flowchart, and C code to solve the given programming problem. It also includes the output for each code example.
1. Page 1 of 68
Fatima Aliasgher Portfolio:
Class: XB
Comp Practicals
Practical No 1:
find the volume of a cube, cylinder or sphere:
Algorithm:
Step 1: Start
Step 2: Input Length of cube
Step III: Input radius and height of cylinder respectively
Step 4: Input radius of Sphere
Step 5: A1= l*l*l
Step 6: A2=3.14*r1*r1*h
Step 7: A3= (4/3)*3.14*r2*r2*r2
Step 8: Output A1
Step 9: Output A2
Step 10: Output A3
Step 11: Stop
2. Page 2 of 68
Flowchart:
Start
Stop
Input l
Input r1, h
A1=l*l*l
A2=3.14*r1*r1*h
A3=4/3*r2*r2*r2*
Output A2
Input r2
Output A1
Output A3
3. Page 3 of 68
Programming:
#include <stdio.h>
int main()
{
int r,h,a,cylinder,cube;
float r1,sphere;
printf("enter radius and height of a cylinder:");
scanf("%d%d",&r,&h);
printf("enter length of a cube:");
scanf("%d",&a);
printf("enter radius of a sphere:");
scanf("%f",&r1);
cylinder=3.14*r*r*h;
cube=a*a*a;
sphere=(4*3.14*r1*r1*r1);
printf("n volume of cylinder is%d",cylinder);
printf("n volume of cube is %d",cube);
printf("n volume of sphere is %f",sphere);
}
Output:
4. Page 4 of 68
Practical No 2:
find the area of a triangle, parallelogram, rhombus and trapezoid.
Algorithm:
Step 1: Start
Step 2: Input base and height respectively of triangle
Step 3: A= b*h/2
Step 4: Output A
Step5: Stop
Flowchart:
Start
Stop
Input b, h
Output A
A=b*h/2
5. Page 5 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float h, b, A;
printf("Enter base and height of the triangle: ");
scanf("%f %f", &b, &h);
A=h*b/2;
printf("nThe area of triangle is %6.2f", A);
getch();
}
Output:
6. Page 6 of 68
Practical No 3:
find the area of a triangle, PARALLELOGRAM , rhombus and trapezoid.
Algorithm:
Step 1: Start
Step2: Input base and height respectively of parallelogram
Step 3: A= b*h
Step 4 : Output A
Step 5: Stop
Flowchart:
Start
Stop
Input b, h
Output A
A=b*h
7. Page 7 of 68
Program:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float h, b, A;
printf("Enter base and height of the parallelogram: ");
scanf("%f %f", &b, &h);
A=h*b;
printf("nThe area of parallelogram: %6.2f", A);
getch();
}
Output:
8. Page 8 of 68
Practical No 4:
find the area of a triangle, parallelogram, rhombus and trapezoid.
Algorithm:
Step 1: Start
Step 2: Input the two diagonals of the Rhombus
Step3: A= p*q/2
Step 4: Output A
Step 5: Stop
Flowchart:
Start
Stop
Input p, q
Output A
A=p*q/2
9. Page 9 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float p, q, A;
printf("Please enter the two diagonals of the Rhombus: ");
scanf("%f %f", &p, &q);
A=p*q/2;
printf("nThe area of parallelogram is %6.2f", A);
getch();
}
Output:
10. Page 10 of 68
Practical No 5:
find the area of a triangle, parallelogram, rhombus and trapezoid.
Algorithm:
STEP 1: Start
Step 2: Input the the two sides of Trapezoid
Step 3: Input height of Trapezoid
Step 4: A= p*q/2
Step 5: Output A
Step 6: Stop
Flowchart:
Start
Stop
Input s1, s2
Output A
A=(s1+s2)*h/2
Input h
11. Page 11 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float s1, s2, h, A;
printf("Please Enter the 2 sides of Trapezoid: ");
scanf("%f %f", &s1, &s2);
printf("nPlease enter height of Trapezoid: ");
scanf("%f", &h);
A=(s1+s2)*h/2;
printf("nThe area of Trapezoid is %6.2f", A);
getch();
}
Output:
12. Page 12 of 68
Practical No 6:
calculate the exponent of a given number.
Algorithm:
Step 1: Start
Step 2: result=1
Step 3: Input the base
Step 4: Input the power
Step 5: k=1
Step 6: For k<=exp THEN GOTO Step7 otherwise GOTO Step10
Step 7: prod= prod*n
Step 8: k=k+1
Step 9: For k<=exp THEN GOTO Step7 otherwise GOTO Step10
Step 10: Output prod
Step 11: Stop
13. Page 13 of 68
Flowchart:
Start
Stop
Input n
Output prod
Input exp
k=1
result=1
prod=prod*n
For k=k+1
Yes
No
14. Page 14 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, exp, k, prod=1;
printf("Enter the base number: ");
scanf("%d", &n);
printf("Enter the power/exponent: ");
scanf("%d", &exp);
for (k=1; k<=exp; k++)
{
prod=prod*n;
}
printf("n%d^%d is %d", n, exp, prod);
getch(); }
Output:
15. Page 15 of 68
Practical No 7:
convert Celsius to Fahrenheit temperature and vice versa.
Algorithm:
Step 1: Start
Step 2: Input temperature in Celsius(C)
Step 3: F=C*1.8+32
Step 4: Output F
Step 5: Stop
Flowchart:
Start
Stop
Input C
Output F
F=C*1.8+32
16. Page 16 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float C, F;
printf("Please enter temperature in degrees Celsius: ");
scanf(" %f", &C);
F=C*1.8+32;
printf("nThe temperature in Fahrenheit is %6.2f", F);
getch();
}
Output:
17. Page 17 of 68
Practical No 8:
convert Celsius to Fahrenheit temperature and vice versa.
Algorithm:
Step 1: Start
Step 2: Input temperature in Fahrenheit
Step 3: C=F-32,1.8
Step 4: Output C
Step 5: Stop
Flowchart:
Start
Stop
Input F
Output C
C=(F-32)/1.8
18. Page 18 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float C, F;
printf("Please enter temperature in degrees Fahrenheit: ");
scanf(" %f", &F);
C=(F-32)/1.8;
printf("nThe temperature in Celsius is %6.2f", C);
getch();
}
Output:
19. Page 19 of 68
Practical No 9:
Prepare an Electricity Bill.
Algorithm:
Step 1: Start
Step 2: Input price unit and gst
Step 3: bill= price*unit
Step 4: tax= bill*gst/100
Step 5: total-bill= bill+tax
Step 6: Output total-bill
Step 7: Stop
Flowchart:
Start
Stop
Input price, unit, gst
Output tot_bill
bill=price*unit
tax=bill*gst/100
20. Page 20 of 68
Programming:
#include<stdio.h>
int main()
{
float bill, units;
printf("Enter the units consumed=");
scanf("%f",&units);
if(units<=50 && units>=0)
{
bill=units*3.50;
printf("Electricity Bill=%f Rupees",bill);
}
else if(units<=100 && units>50)
{
bill=50*3.50+(units-50)*4;
printf("Electricity Bill=%f Rupees",bill);
}
Output:
21. Page 21 of 68
Practical No 10:
Calculate GCD of two numbers
Algorithm:
Step 1: Start
Step 2: Input positive integers respectively
Step 3: a=n1 b=n2
Step 4: While b!=0 THEN GOTO Step otherwise GOTO
Step 5: t=b
Step 6: b= a%b
Step 7: a=t
Step 8: While b!=0 THEN GOTO Step otherwise GOTO
Step 9: Output a
Step 10: Stop
22. Page 22 of 68
Flowchart:
Start
Stop
Input n1, n2
Output a
a=n1
b=n2
t=b
b=a%b
While
b!=0?
Yes
No
23. Page 23 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n1,n2,a,b,t,gcd;
printf("nEnter two integers : ");
scanf("%d %d",&n1, &n2);
a=n1;
b=n2;
while(b!=0)
{
t=b;
b=a%b;
a=t;
}
printf("nThe GCD of the numbers is %d", a);
getch();}
Output:
24. Page 24 of 68
Practical 11:
Find the intrest in an amount:
Algorithm:
Step 1: Start
Step 2: Input actual amount(actual)
Step 3: Input interest rate
Step 4: Input time period(time)
Step 5: interest=actual*rate*time/100
Step 6: Output interest
Step 7: Stop
25. Page 25 of 68
Flowchart:
Start
Stop
Input actual
Input rate
Input time
Output interest
interest=actual*rate*time/100
26. Page 26 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float actual, rate, time, interest;
printf("Enter the actual amount: ");
scanf("%f", &actual);
printf("Enter the interest rate(amount per year): ");
scanf("%f", &rate);
printf("Enter the time period (in years): ");
scanf("%f", &time);
interest=(actual*rate*time)/100;
printf("The interest on your amount is now %6.1f");
getch();
}
Output:
27. Page 27 of 68
Practical No 12:
Find the sum, product, and average of five given numbers
Algorithm:
Step 1: Start
Step 2: Input five numbers
Step 3: sum= a+b+c+d+e
Step 4: prod=a*b*c*d*e
Step 5: avg= a+b+c+d+e/5
Step 6: Output sum
Step 7: Output prod
Step 8: Output avg
Step 9: Stop
28. Page 28 of 68
Flowchart:
Start
Stop
Input a, b, c, d, e
Output avg
Output sum
Output prod
prod=a*b*c*d*e
sum=a+b+c+d+e
avg=(a+b+c+d+e)/5
29. Page 29 of 68
Program:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float a, b, c, d, e, sum, prod, avg;
printf("Enter the five numbers: ");
scanf("%f %f %f %f %f", &a, &b, &c, &d, &e);
sum=a+b+c+d+e;
prod=a*b*c*d*e;
avg=sum/5;
printf("nThe Sum of five numbers is %.2f", sum);
printf("nThe Product of five numbers is %.2f", prod);
printf("nThe Average of five numbers is %.2f", avg);
getch();
}
Output:
30. Page 30 of 68
Practical No 13:
find acceleration of a moving object with given mass and the force applied.
Algorithm:
Step1: Start
Step2: Input mass of moving object
Step3: Input Force applied
Step4: a=F/m
Step5: Output F
Step6: Stop
Flowchart:
Start
Stop
Input m
Input F
Output F
a = F/m
31. Page 31 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
float m, a, F;
printf("Enter the mass(Kg)) of moving object: ");
scanf("%f", &m);
printf("Please enter the Force applied: ");
scanf("%f", &F);
a=F/m;
printf("nThe acceleration of moving object is %.2f", a);
getch();
}
Output:
32. Page 32 of 68
Practical No 14:
find even numbers in integers ranging from n1 and n2 (where n1 is greater than n2).
Algorithm:
Step1: Start
Step2: Input range limits n1 and n2 where n1 is greater than n2
Step3: Initialize i to n2
i=n2
Step4: Check if ‘i’ is less than or equal to n1
For i<=n1 THEN GOTO Step5 otherwise GOTO Step9
Step5: Check if remainder of ‘i’ by 2 is equal to 0
If i%2==0 THEN GOTO Step6 otherwise GOTO Step4
Step6: Output i
Step7: i=i+1 THEN GOTO Step4
Step8: Check if ‘i’ is less than or equal to n1
For i<=n1 THEN GOTO Step5 otherwise GOTO Step9
Step9: Stop
33. Page 33 of 68
Flowchart:
For
i<=n1?
i=n2
If
i%2==0?
Output i
Stop
i=i+1
Yes
Yes
No
No
Start
Input n1, n2
34. Page 34 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n1, n2, i;
printf("Enter limits n1 and n2 respectively where n1 is greater than n2: ");
scanf("%d %d", &n1, &n2);
printf("Even numbers in the range %d to %d are:n", n2, n1);
for (i = n2; i <= n1; i++)
{
if (i%2==0)
{
printf("%d ", i);
}
}
getch(); }
Output:
35. Page 35 of 68
Practical No 15:
determine prime numbers in integers ranging from n1 to n2 (where n1 is greater than
n2).
Algorithm:
Step 1: Start
Step 2: Input range limits n1 and n2 respectively where n1 is greater than n2
Step 3: i=n2
Step 4: For i<=n1 THEN GOTO Step5 other GOTO Step16
Step 5: prime=1
Step 6: j=2
Step 7: For j<i THEN GOTO Step8 otherwise GOTO Step12
Step 8: If i%j== 0 THEN GOTO Step9 otherwise GOTO Step 10
Step 9: prime= 0
Step 10: j=j+1 THEN GOTO Step7
Step 11: For j<i THEN GOTO Step8 otherwise GOTO Step12
Step 12: If prime==1 THEN GOTO Step 13 otherwise GOTO Step14
Step 13: Output i
Step 14: i=i+1 THEN GOTO Step4
Step 15: For i<=n1 THEN GOTO Step5 other GOTO Step16
Step 17: Stop
36. Page 36 of 68
Flowchart:
Start
Input n1, n2
For i<=n1?
i=n2
For
j<i?
j=2
prime=1
If
i%j==0?
prime=0
j=j+1
If
prime==1?
Output i
i=i+1
Stop
Yes
Start
Yes
Yes
No
No
Yes
No
No
37. Page 37 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n1, n2, i, j, prime;
printf("Enter limits n1 and n2 where n1 should be greater than n2: ");
scanf("%d %d", &n1, &n2);
printf("The prime numbers from %d to %d are: ", n2, n1);
for (i=n2; i<=n1; i++)
{
prime = 1;
for (j=2; j<i; j++)
{
if (i%j==0)
{
prime=0;
}
}
if (prime==1)
{
printf("%d ", i);
}
}
getch();
}
39. Page 39 of 68
Practical No 16:
Count multiple of a given number lying between two numbers.
Algorithm:
Step 1: Start
Step 2: Input range limits n1 and n2 respectively
Step 3: Input multiple
Step 4: Initialize k to n1 K=n1
Step 5: For k<=n2 THEN GOTO Step6 otherwise GOTO Step10
Step 6: If k%multiple==0 THEN GOTO Step7 otherwise GOTO Step8
Step 7: count=count+1
Step 8: k=k+1 THEN GOTO Step5
Step 9: For k<=n2 THEN GOTO Step6 otherwise GOTO Step10
Step 10: Output count
Step 11: Stop
40. Page 40 of 68
Flowchart:
Start
Input n1, n2
Input multiple
k=n1
For
If
count=count+1
k=k+1
Stop
Yes
Yes
No
No
Output count
41. Page 41 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n1, n2, multiple, k, count = 0;
printf("Enter the lower and upper limits respectively: ");
scanf("%d %d", &n1, &n2);
printf("Enter a number to count multiples: ");
scanf("%d", &multiple);
for (k=n1; k<=n2; k++)
{
if (k%multiple==0)
{
count++;
}
}
printf("The number of multiples of %d is: %d", multiple, count);
getch();}
Output:
42. Page 42 of 68
Practical No 17:
Algorithm:
Step 1: Start
Step 2: Input the number of values(n)
Step 3: max=-2147483648(smallest int value)
Step 4: k=1
Step 5: For k<=n THEN GOTO Step6 otherwise GOTO Step10
Step 6: Input the number(num)
Step 7: If num>max THEN GOTO Step8 otherwise GOTO Step11
Step 8: max=num
Step 9: For k<=n THEN GOTO Step6 otherwise GOTO Step10
Step 10: Output max
Step 11: k=k+1 THEN GOTO Step5
Step 12: Stop
43. Page 43 of 68
Flowchart:
Stop
Input n
Input num
max=num
Output max
k=k+1
Yes
Yesss
No
No
max=-2147483647
44. Page 44 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, k, num;
int max = -2147483647;
printf("Enter the number of values you will use to compare: ");
scanf("%d", &n);
for (k = 1; k<=n; k++)
{
printf("Enter value %d: ", k);
scanf("%d", &num);
if (num>max)
{
max=num;
}
}
printf("The maximum value is %dn", max);
getch();
}
46. Page 46 of 68
Practical No 18:
find the minimum number from input values.
Algorithm:
Step 1: Start
Step 2: Input the number of values(n)
Step 3: min=214748364(largest int value)
Step 4: k=1
Step 5: For k<=n THEN GOTO Step6 otherwise GOTO Step10
Step 6: Input the number(num)
Step 7: If num<min THEN GOTO Step8 otherwise GOTO Step11
Step 8: min=num
Step 9: For k<=n THEN GOTO Step6 otherwise GOTO Step10
Step 10: Output min
Step 11: k=k+1 THEN GOTO Step5
Step 12: Stop
47. Page 47 of 68
Flowchart:
Input n
k=1
k<=n?
Input num
min=num
Output min
k=k+1
Yes
Yes
No
min=2147483647
No
48. Page 48 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, k, num;
int min = 2147483647;
printf("Enter the number of values you will use to compare: ");
scanf("%d", &n);
for (k = 1; k<=n; k++)
{
printf("Enter value %d: ", k);
scanf("%d", &num);
if (num<min)
{
min=num;
}
}
printf("The minimum value is %dn", min);
getch();
}
50. Page 50 of 68
Practical No 19:
determine whether a given number is prime or not.
Algorithm:
Step1: Start
Step2: Input number(n)
Step3: j=0
Step4: k=2
Step5: For k<n THEN GOTO Step6 otherwise GOTO Step10
Step6: If n%k==0 THEN GOTO Step7 otherwise GOTO Step8
Step7: j=j+1
Step8: k=k+1 THEN GOTO Step5
Step9: For k<n THEN GOTO Step6 otherwise GOTO Step10
Step10: If j==0 THEN GOTO Step11 otherwise GOTO Step12
Step11: Output “This is a Prime Number” THEN GOTO Step12
Step12: Output “This is not a prime number” THEN GOTO Step12
Step13: Stop
51. Page 51 of 68
Flowchart:
Start
Input n
j=0
k=2
k<n?
k=k+1
j=j+1
j==0?
Output “This is a prime number”
Output ”This is not a prime number”
Stop
yes
Yes
Yes
No
No
No
52. Page 52 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, k, j;
printf("Enter a positive integer: ");
scanf("%d", &n);
j=0;
for (k=2; k<n; k++)
{
if (n%k==0)
{
j=j+1;
}
}
if (j==0)
{
printf("This is a prime number");
}
else
{
printf("This is not a prime number");
}
getch();
}
54. Page 54 of 68
Practical No 20:
display the larger one out of the three given unequal numbers.
Algorithm:
Step1: Start
Step2: Input three numbers(a, b, c) respectively
Step3: If a>b THEN GOTO Step4 otherwise GOTO Step5
Step4: largest=a THEN GOTO Step6
Step5: largest=b THEN GOTO Step6
Step6: If largest>c THEN GOTO Step7 otherwise GOTO Step8
Step7: Output largest THEN GOTO Step9
Step8: Output c THEN GOTO Step9
Step9: Stop
55. Page 55 of 68
Flowchart:
Start
Input a, b, c
If
a>b?
If
largest>c?
largest=b
largest=a
Output largest
Stop
Output c
Yes
Yes
No
No
56. Page 56 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a, b, c, largest;
printf("Enter three unequal numbers respectively: ");
scanf("%d %d %d", &a, &b, &c);
if (a>b)
{
largest=a;
}
else
{
largest=b;
}
if (largest>c)
{
printf("The largest number is: %dn", largest);
}
else
{
printf("The largest number is: %dn", c);
}
getch();
}
58. Page 58 of 68
Practical No 21:
assign grade to a subject based on the achieved marks.
Algorithm:
Step1: Start
Step2: Input Percentage Marks(M) of Subject
Step3: If M>=80 AND M<=100 THEN Output “Grade A1” otherwise GOTO Step4
Step4: If M>=70 AND M<80 THEN Output “Grade A” otherwise GOTO Step5
Step5: If M>=60 AND M<70 THEN Output “Grade B” otherwise GOTO Step6
Step6: If M>=50 AND M<60 THEN Output “Grade C” otherwise GOTO Step8
Step7: If M>=40 AND M<50 THEN Output “Grade D” otherwise GOTO Step9
Step8: If M>=33 AND M<40 THEN Output “Grade E” otherwise GOTO Step10
Step9: Output “You failed”
Step10: Stop
59. Page 59 of 68
Flowchart:
Start
Input M
Output “Grade D”
If
If
If
If
If
If
Output “You failed”
Stop
Output “Grade C”
Output “Grade A1”
Output “Grade A”
Output “Grade B”
Output “Grade E”
60. Page 60 of 68
Programming:
#include<conio.h>
void main(void)
{
int M;
printf("Enter the percentage marks of the subject: ");
scanf("%d", &M);
if (M>=80 && M<=100) {
printf("nGrade A1");
}
else if (M>=70 && M<80) {
printf("nGrade A");
}
else if (M>=60 && M<70) {
printf("nGrade B");
}
else if (M>=50 && M<60) {
printf("nGrade C");
}
else if (M>=40 && M<50) {
printf("nGrade D");
}
else if (M>=33 && M<40){
printf("nGrade E");
}
else {
printf("nYou failed");
}
getch();
}
62. Page 62 of 68
Practical No 22:
find the sequence of odd number starting from a given number.
Algorithm:
Step1: Start
Step2: Input starting number(n)
Step3: i=n
Step4: While i<=n+20 THEN GOTO Step5 otherwise GOTO Step8
Step5: If i%2==1 THEN GOTO Step6 otherwise GOTO Step7
Step6: Output i
Step7: i=i+1 THEN GOTO Step4
Step8: Stop
63. Page 63 of 68
Flowchart:
Start
Stop
i=n
i<=n+20?
i%2==1?
i=i+1
Yes
Yes
No
No
64. Page 64 of 68
Programming:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, i;
printf("Enter a starting number: ");
scanf("%d", &n);
printf("Odd numbers starting from %d are: ", n);
i=n;
while (i<=n+20)
{
if (i%2==1)
{
printf("%d ", i);
}
i++;
}
getch();
}