Computer Practical 10th Class
Computer Practical 10th Class
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
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.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
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
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
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
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():
}
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
}
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