0% found this document useful (0 votes)
6 views9 pages

Computer Practical 10th Class

The document contains a series of C programming exercises from a secondary school curriculum, including algorithms and code for tasks such as calculating sums, averages, products, simple interest, temperature conversions, and checking leap years. Each exercise includes a step-by-step algorithm, flowchart description, and corresponding C code. The document serves as a practical guide for students learning programming concepts and syntax in C.

Uploaded by

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

Computer Practical 10th Class

The document contains a series of C programming exercises from a secondary school curriculum, including algorithms and code for tasks such as calculating sums, averages, products, simple interest, temperature conversions, and checking leap years. Each exercise includes a step-by-step algorithm, flowchart description, and corresponding C code. The document serves as a practical guide for students learning programming concepts and syntax in C.

Uploaded by

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

GOVT. BOYS SECONDARY SCHOOL CHAK NO.

99/P RAHIM YAR KHAN

Q.1: Write C Program that input two numbers. Calculate sum and average of two numbers.
Algorithm Flowchart
Step 1: start.
Step 2: read a, b;
Step 3: sum = a + b
Step 4: avg=sum/2;
Step 5: print sum
Step 6: print avg;
Step 7: stop.
Program
#include <stdio.h>
#include <conio.h>
main()
{
int a,b, sum;
float avg;
printf("Enter First Number :");
scanf("%d",&a);
printf("Enter Second Number :");
scanf("%d",&b);
sum=a+b;
avg= (a+b)/2;
printf("\nSum of %d and %d is = %d",a,b,sum);
printf("\nAverage of %d and %d is = %f",a,b,avg);
} Output

Q.2: Write C Program that input two numbers. Calculate product of two numbers.
Algorithm Flowchart
Algorithm to multiply two numbers in c:
Step 1: start
Step 2: accept number one
Step 3: accept number two
Step 4: multiply both the numbers
Step 5: print the result.
Step 6: end
Program
#include <stdio.h>
#include <conio.h>
main()
{
double a, b, product;
printf("Enter Two Numbers: ");
scanf("%lf %lf", &a, &b);
product = a * b;
printf("Product = %f", product);
} Output

Hafiz Muhammad Ramzan Sani SST (CS) Page | 1


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.2: Write C Program to calculate simple interest with explanation


Algorithm Flowchart
Step 1: Start
Step 2: Read principal amount, rate and time
Step 3: Calculate interest using formula si= ((amount*rate*time)/100)
Step 4: Print simple interest
Step 5: Stop

Program
#include <stdio.h>
#include <conio.h>
main()
{
floatp, t, r, si;
printf("Program to calculate simple interest\n");
printf("Enter principle amount: ");
scanf("%f", &p);
printf("Enter time (in years): ");
scanf("%f", &t);
printf("Enter rate: ");
scanf("%f", &r);
si = (p * t * r) / 100;
printf("Simple Interest = %f", si);
} Output

Q.4: Write C Program to convert Fahrenheit to Celsius and Celsius to Fahrenheit.


Algorithm Flowchart
Step 1: Start
Step 2: Read the temperature given in degree Fahrenheit.
Step 3: Convert the temperature Fahrenheit into
Celsius using the formula : C=(F-32)* 5/9
Step 4: Print the Celsius value of temperature.
Step 5: End
Program)
# include<stdio.h>
#include <conio.h>
main()
{
float c, f;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
c = (f-32)*5/9;
printf("%.2f Fahrenheit = %.2f Celsius", f, c);
} Output

Hafiz Muhammad Ramzan Sani SST (CS) Page | 2


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.5: Write C Program to convert Celsius to Fahrenheit.


Algorithm Flowchart
Step 1: Start
Step 2: Read the temperature given in degree Celsius.
Step 3: Convert the temperature Celsius into Fahrenheit
using the formula : F=C*5/9+32
Step 4: Print the Fahrenheit temperature.
Step 5: End
Program
#include<stdio.h>
#include<conio.h>
main()
{
float c,f;
printf("Enter Temperature in Celsius =");
scanf("%f", &c);
f=(9.0/5.0)*c+32;
printf("Fahrenheit is =%.2f",f);
getch();
} Output

Q.6: Write C Program to check the given year is a leap year or not.
Algorithm Flowchart
To determine whether a year is a leap year, follow these steps:

Step 1: Start
Step 2: Enter Year
Step 3: if the year is evenly divisible by 4, go to step 5.
Step 4: Print Not a Leap Year, go to step 8.
Step 5: Print Leap Year
Step 6: End

Program
#include <stdio.h>
#include<conio.h>
main()
{
int y;
printf("Please Enter a Year: ");
scanf("%d", &y);
if(y%4==0)
printf("Given Year %d is a Leap Year.", y);
else
printf("Given Year %d is not a Leap Year.", y);
} Output

Hafiz Muhammad Ramzan Sani SST (CS) Page | 3


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.7: Write C Program to input a number and Calculate square root of the number.

Algorithm Flowchart
Step 1: Start
Step 2: Enter the number for square root.
Step 3: Calculate the square root by sqrt() function.
Step 4: Print the result.
Step 5: Stop
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int num;
double result;
printf("c Program to find Square root \n");
printf("Enter a Number to Find Square Root: ");
scanf("%d",&num);
result = sqrt(num);
printf("Square Rroot of %d is = %f", num, result);
} Output

Q.8: Write C Program to Calculate the Power of the number.


Algorithm Flowchart

Step 1: Start
Step 2: Input b, p
Step 3: Set prod=1 and i=1
Step 4: Repeat the steps 5 and 6 until i less than p
Step 5: Set prod=prod*b
Step 6: Set i++
Step 7: Print product
Step 8: Stop

Program
#include<conio.h>
#include<stdio.h>
main()
{
int b, p, prod=1;
printf("Enter an Integer for Base =");
scanf("%d",&b);
printf("Enter an Integer for Power=");
scanf("%d",&p);
for (int i=1; i<=p; i++)
{
prod=b*prod;
}
printf("Power of %d raised to %d is =%d", b, p, prod);
getch();
} Output

Hafiz Muhammad Ramzan Sani SST (CS) Page | 4


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.9: Write C Program to print it is even or odd number.


Algorithm Flowchart
Step 1: Start
Step 2: Input number
Step 3: If num mod 2 equal to zero goto step 4 else step 5
Step 4: Print “num is Even” go to step 6.
Step 5: Print “num is Odd”
Step 6: Stop
Program
#include<stdio.h>
#include<conio.h>
main()
{
int num;
printf("Enter a Number to Check Even or Odd = ");
scanf("%d",&num);
if(num%2==0)
{
printf("The Given Number %d is Even",num);
}
else
{
printf("The Given Number %d is Odd",num); Output
}
}

Q.10: Write C Program to swap two numbers using third variable.


Algorithm Flowchart
Step 1: Start
Step 2: Declare and Input a, b and declare c
Step 3: Set c=a;
Step 4: Set a=b;
Step 5: Set b=c;
Step 6: Print a, b.
Step 7: Stop

Program
#include<stdio.h>
#include<conio.h>
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("Value of a after swaping: %d\n",a);
printf("Value of b after swaping: %d",b);
} Output

Hafiz Muhammad Ramzan Sani SST (CS) Page | 5


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.11: Write C Program to swap two numbers without using third variable.
Algorithm Flowchart
Step 1: Start
Step 2: Input a, b
Step 3: Set a=a+b;
Step 4: Set b=a-b;
Step 5: Set a=a-b;
Step 6: Print a, b.
Step 7: Stop
Program
#include<stdio.h>
#include<conio.h>
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("Value of a after swaping: %d\n",a);
printf("Value of b after swaping: %d",b);
getch(); Output
}
Q.12: Write C Program that input three numbers and find out the Maximum number.
Algorithm Flowchart
Step 1: Start
Step 2: Input a,b,c
Step 3: If a is greater than b and c then goto step 5
Step 4: If b is greater than a and c then goto step 6 else 7
Step 5: Print a goto step 8
Step 6: Print b goto step 8
Step 7: Print c
Step 8: End
Program
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
printf("Enter the value of c: ");
scanf("%d",&c);
if(a>=b && a>=c)
printf("a is Greatest which is=%d",a);
if(b>=a && b>=c)
printf("b is Greatest which is =%d",b);
if(c>=a && c>=b)
printf("c is Greatest which is =%d",c); Output
getch():
}

Hafiz Muhammad Ramzan Sani SST (CS) Page | 6


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.13: Write C Program to calculate the cube of a given number.


Algorithm Flowchart
Step 1: Start
Step 2: Input num
Step 3: Cube=num *num*num
Step 4: Print Cube
Step 5: Stop

Program
#include<stdio.h>
#include<conio.h>
main()
{
float num,cube;
printf("Enter a number to calculate cube: ");
scanf("%f", &num);
cube = num * num * num;
printf("Cube of %.2f = %.2f",num, cube);
getch(); Output
}

Q.14: Write C Program to calculate factorial using iterative method.


Algorithm Flowchart
Step 1: Start
Step 2: Input num
Step 3: Declare variable n, fact, i
Step 4: Set fact=1 and i=1
Step 5: repeat until i<=num
5.1 fact=fact*i
5.2 i=i+1
Step 6: Print fact
Step 7: Stop.

Program
#include<stdio.h>
#include<conio.h>
int fact(int num)
{
int i=1,fact=1;
while(i<=num)
{
fact=fact*i;
i++;
}
return fact;
}
main()
{
int i, num, factorial=1;
printf("Enter a Number ");
scanf("%d",&num);
printf("factorial of %d is: %d",num,fact(num) );
} Output

Hafiz Muhammad Ramzan Sani SST (CS) Page | 7


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.15: Write C Program to print the table up to specific number (limit).


Algorithm Flowchart
Step 1: Start
Step 2: Input t and l
Step 3: Set i=1
Step 4: Repeat umtil i<=l
4.1 Print t,i,txi;
4.2 i++
Step 5: Stop
Program
#include<conio.h>
#include<stdio.h>
main()
{
int t,l;
printf("Enter Table No. =");
scanf("%d",&t);
printf("Enter Table End Limit =");
scanf("%d",&l);
for(int i=1;i<=l;i++)
{
printf(" %d\tx\t%d\t=\t%d \n",t,i,t*i);
}
getch();
}
Output
Q.16: Write C Program to print stars in this pattern.
***** Flowchart
****
***
**
*
Algorithm
Step 1: Start
Step 2: Set i=5
Step 3: Repeat until i>=l
3.1: j=i
3.2: Repeat until j>=1
3.2.1: Print t *
3.2.2: j++
3.3: Print “\n”
3.4: i++
Step 4: Stop
Program
#include<conio.h>
#include<stdio.h>
main()
{ for(int i=5;i>=1;i--)
{ for(int j=i; j>=1;j--)
{
printf("*");
}
printf("\n");
}
getch();
}

Hafiz Muhammad Ramzan Sani SST (CS) Page | 8


GOVT. BOYS SECONDARY SCHOOL CHAK NO. 99/P RAHIM YAR KHAN

Q.17: Write C Program to print stars in this pattern.


* Flowchart
**
***
****
*****
Algorithm
Step 1: Start
Step 2: Set i=1
Step 3: Repeat until i<=5
3.1: j=1
3.2: Repeat until j<=i
3.2.1: Print *
3.2.2: j++
3.3: Print “\n”
3.4: i++
Step 4: Stop
Program
#include<conio.h>
#include<stdio.h>
main()
{
for(int i=1;i<=5;i++)
{
for(int j=1; j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Hafiz Muhammad Ramzan Sani SST (CS) Page | 9

You might also like