10TH Class All Activities and Excercise Program
10TH Class All Activities and Excercise Program
10
/ Activity 2.2**********************************************************************
Write a program that shows your first name in Uppercase and your last name in lower case letters on
screen.
***********************************************************************************/
#include <stdio.h> OUTPUT:
int main()
{ HAMMAD hassan
printf("HAMMAD hassan");
/ Activity 2.3**********************************************************************
Write a program that takes roll number, percentage of marks and grade from user as input.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main() OUTPUT:
{ Please Enter Your Roll Number:101
int rollnumber; // input rollnumber of student Please Enter Your Percentage:75.0
float percentage; // input percentage of student Please Enter Your Grade:A
char grade; // input grade of student
~2~
/ Activity 2.4**********************************************************************
Write a program that takes as input the length of one side of a square and calculates the area of
square.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> OUTPUT:
int main() Please Enter One Side of Square Length:12
{ Area of Square is: 144
int one_side_length, area_of_square;
Write a program that takes as input the number of balls in jar A and the number of balls in jar B. The
program calculates and displays the total number of balls.
***********************************************************************************/
#include <stdio.h>
int main() OUTPUT:
{ Please Enter the number of balls in Jar A: 50
int total_balls, jarA_balls,jarB_balls; Please Enter the number of balls in Jar B: 20
printf("Please Enter the number of balls in Jar A:"); Total Number of Balls are: 70
scanf(“%d”,&jarA_balls);
total_balls= jarA_balls+jarB_balls;
~3~
/ Activity 2.6**********************************************************************
Write a program that takes original price of a shirt and discount percentage from user. Program
should display the original price of shirt, discount on price and price after discount.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int original_price, discount_price, discount_percentage, price_after_dicount;
Write a program that takes 2 digit number from user, computes the product of both digits and show
the output.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main() OUTPUT:
{ Please enter the first digit number: 50
Please enter the second digit number:10
int digit1, digit2;
Product of first and second digit is:500
printf (“Please enter the first digit number:”);
scanf(“%d”,& digit1);
printf (“Please enter the second digit number:”);
scanf(“%d”,& digit2);
printf(“\nProduct of first and second digit is: %d”, digit1*digit2);
getch();
}
~4~
/ Activity 2.8**********************************************************************
Write a program that takes seconds as input and calculates equivalent number of hours, minutes and
seconds.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{ OUTPUT:
float seconds, minutes, hours; Please enter the seconds:3600
/ Activity 2.9**********************************************************************
~5~
/ Exercise 1**********************************************************************
Write a program that should take working hours and overtime hours of employee as input. The
program should calculate and display the total salary of employee.
***********************************************************************************/
#include <stdio.h>
int main()
{
int Basic_Salary, Overtime_Salary, Total_Salary,Working_Hours, Overtime_Hours;
~6~
/ Exercise 3**********************************************************************
Write a program that display the following output using single printf statement:
* * * *
1 2 3 4
***********************************************************************************/
#include <stdio.h>
int main()
{
printf("*\t*\t*\t*\t\n1\t2\t3\t4");
}
/ Exercise 4**********************************************************************
Write a program that display the following output using single printf statement:
I am a Boy
I live in Pakistan
I am a proud Pakistani
***********************************************************************************/
#include <stdio.h>
int main() OUTPUT:
{ I am Boy
printf("I am Boy\nI Live in Pakistan\nI am a Proud Pakistani"); I Live in Pakistan
I am a Proud Pakistani
}
/ Exercise 5**********************************************************************
A clothing brand offers 15% discount on each item. A lady buys 5 shirts from this brand. Write a
program that calculates total price after discount and amount of discounts availed by lady. Original
prices of the shirts are: Shirt1 = 423, Shirt1 = 320, Shirt1 = 270, Shirt1 = 680, Shirt1 = 520.
***********************************************************************************/
#include <stdio.h>
int main() OUTPUT:
{ Total Price is:2213
int Shirt1=423,Shirt2=320,Shirt3=270,Shirt4=680,Shirt5=520; Total Discount is:331
int Total_Price, Total_Discount, Final_Price; Final Price is:1882
Total_Price=Shirt1+Shirt2+Shirt3+Shirt4+Shirt5;
Total_Discount=(Total_Price*15)/100;
Final_Price=Total_Price - Total_Discount;
printf("Total Price is:%d \nTotal Discount is: %d \nFinal Price is: %d",Total_Price,Total_Discount,Final_Price);
}
~7~
/ Exercise 6**********************************************************************
Write a program that swaps the values of two integer variable without help of any third variable.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
OUTPUT:
int main()
Before swap a=10 b=20
{
After swap a=20 b=10
int a=10, b=20;
/ Exercise 7**********************************************************************
Write a program that takes a 5 digit number as input, calculate and displays the sum of first and last
digit of number.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> OUTPUT:
int main() Enter a number with length 5 digits:12345
{ The Sum of first and fifth digit is:6
int number;
~8~
/ Exercise 8**********************************************************************
Write a program that takes monthly income and monthly expense of the user like electricity bill, gas
bill, food expense.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int Monthy_Income, Electricity_Bill, Gas_bill, Food_Expense, Monthy_Expenses, Monthy_Savings,Yearly_Expenses;
Monthy_Savings=Monthy_Income + Monthy_Savings;
getch();
}
~9~
/ Exercise 9**********************************************************************
Write a program that takes a character and number of steps as input from user. Program should then
jump number of steps from of steps from that character.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
OUTPUT:
{
Enter Character:a
char c;
Enter Steps:2
int steps;
New Character:c
printf("Enter Character:");
scanf("%c",&c);
printf("Enter Steps:");
scanf("%d",&steps);
int x = c + steps;
Write a program that takes radius of a circle as input. The program should calculate and display the
area of circle.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> OUTPUT:
int main() Please Enter The Radius of Circle:36
{ Area of Circle is:4069.44
float radius;
~ 10 ~
COMPUTER SCIENCE UNIT 3
/ Activity 3.1**********************************************************************
Write a program that takes the age of a person as an input and displays “Teenager” if the age lies
between 13 and 19.
***********************************************************************************/
#include <stdio.h>
int main()
OUTPUT:
{
int age; Enter Your Age:15
You are Teenager
printf(“ Enter Your Age:”);
scanf(“%d”, &age);
if(year %4 == 0)
printf(“Leap Year”);
else
printf(“NOT a Leap Year”);
}
~ 11 ~
/ Activity 3.3**********************************************************************
Write a program that takes the value of body temperature of a person as an input and displays “You
have fever”. If body temperature is more than 98.6 otherwise displays “You don’t have fever.”
***********************************************************************************/
#include <stdio.h>
int main()
OUTPUT:
{
float temp; Enter Body Temperature:98
***********************************************************************************/
#include <stdio.h>
int main()
{
float percentage; OUTPUT:
~ 12 ~
/ Activity 3.5**********************************************************************
***********************************************************************************/
#include <stdio.h>
#include <conio.h> OUTPUT:
int main() Enter First Number:2
{ Enter Second Number:6
int a,b,c ; Enter Choice from 1 to 4:3
if(c == 1)
printf(“Addition %d\n” , a + b);
if(c == 2)
printf(“Subtraction %d\n” , a - b);
if(c == 3)
printf(“Multiplication %d\n” , a * b);
if(c == 4)
printf(“Division %d\n” , a / b);
getch();
}
~ 13 ~
/ Activity 3.6**********************************************************************
Write a program that finds and displays area of triangle , parallelogram, rhombus or trapezium
according to the choice of user.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int choice ;
float triangle,parallelogram;
printf(“ Find Area\n”);
printf(“ 1. Triangle\n 2. Parallelogram \n Enter Your Choice:”);
scanf(“%d”, & choice);
if(choice==1)
{ OUTPUT:
float base,height;
printf(“ Enter Base:”); Find Area
scanf(“%f”,&base); 1. Triangle
printf(“ Enter Height:”); 2. Parallelogram
scanf(“%f”, &height); Enter Your Choice:1
triangle = 0.5 *base * height; Enter Base:30
printf(“ Area of a triangle is: %f”, triangle); Enter Hieght:40
} Area of a triangle is: 600.000000
else if(choice==2)
{
float base,height;
printf(“ Enter Base:”);
scanf(“%f”,&base);
printf(“ Enter Height:”);
scanf(“%f”, &height);
parallelogram = base * height;
printf(“ Area of a triangle is: %f”, parallelogram);
}
else
printf(“invalid choice”);
getch();
}
~ 14 ~
/ Exercise 1**********************************************************************
Write a program that takes two integers as input and tells whether first one is a factor of the second
one?
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
OUTPUT:
{
int num1, num2; Please Enter The First Number: 6
Please Enter The Second Number: 12
printf("Please Enter The First Number:"); First Number is Factor of Second Number
scanf("%d",&num1);
printf("Please Enter The Second Number:");
scanf("%d",&num2);
if(num2%num1==0)
printf(“First Number is Factor of Second Number”);
else
printf(“First Number is NOT A Factor of Second Number”);
getch();
}
/ Exercise 2**********************************************************************
Write a program that takes a number as input and display “YES” if the input number is a multiple of 3,
and has 5 in unit’s place e.g. 15, 75.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main() OUTPUT:
{
Please Enter a Number:15
int num;
Yes
~ 15 ~
/ Exercise 3**********************************************************************
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main() OUTPUT:
{
int total_bill; Please Enter the Total Bill:5000
Discount =35
printf("Please Enter the Total Bill:"); Discount price =1750.000000
scanf("%d", & total_bill);
getch();
}
~ 16 ~
/ Exercise 4**********************************************************************
Write a program that takes as input, the original price and sale price of a product and tells whether
the product is sold on profit or loss. The program should also tell the profit/loss percentage.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
OUTPUT:
int main()
{ Please Enter the Total Original Price:800
float org_price, sale_price, profit, loss;
Please Enter the Total Sale Price:1000
printf("Please Enter the Total Original Price:");
Your Profit is:200.00 Your Profit Percentage is:50.00
scanf("%f", & org_price);
printf("Please Enter the Total Sale Price:");
scanf("%f", & sale_price);
getch();
}
~ 17 ~
/ Exercise 5**********************************************************************
Write a program that takes as input, the lengths of 3 sides of a triangle and tells whether it is a right
angle triangle or not. For right angle triangle,
~ 18 ~
/ Exercise 6**********************************************************************
Write a program that takes as input, the obtained and total marks of Matric, Intermediate, Entrance
Test. The program shulod tekk whether the student is eligible or not.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{
float obt_mark_Matric , total_mark_Matric , obt_mark_Inter , total_mark_Inter, obt_mark_Test,
total_mark_Test;
float matric_percentage, inter_percentage, test_percentage;
if(matric_percentage >= 60.0 && inter_percentage >= 65.0 && test_percentage >= 65.0 )
printf(“ \nThe Student is Eligible. ”);
else
printf(“ \nThe Student is NOT Eligible. ”);
getch();
}
~ 19 ~
/ Exercise 7**********************************************************************
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int salary, experience, bonus_task; OUTPUT:
Please Enter the Salary of Employee:10000
printf("Please Enter the Salary of Employee:"); Please Enter the Experience of Employee:2
scanf("%d", & salary); Please Enter the Bouns of Employee:5
printf("Please Enter the Experience of Employee:"); Bouns is: 1500
scanf("%d", & experience);
printf("Please Enter the Bouns of Employee:");
scanf("%d", & bonus_task);
~ 20 ~
COMPUTER SCIENCE UNIT 4
Programming Time 4.5: Write a program that 5 times displays the numbers from 1-10 on
computers screen.
#include <stdio.h>
int main() Output:
{ 12345678910
for (int i= 1; i<=5; i++) 12345678910
{ 12345678910
for (int j=1; j<=10; j++) 12345678910
{ 12345678910
printf(“%d”,j);
}
printf(“\n”);
}
}
Programming Time 4.6: Write a program to display the following pattern of stars on
screen.
*
**
***
****
*****
******
. #include <stdio.h>
int main() Output:
{ *
for (int i= 1; i<=6; i++) **
{ ***
****
for (int j=1; j<=i; j++)
*****
{
******
printf(“*”);
}
printf(“\n”);
}
}
~ 21 ~
/ Activity 4.1**********************************************************************
/ Activity 4.2**********************************************************************
Write a program that displays the tables of 2, 3, 4, 5 and 6.
***********************************************************************************/
#include <stdio.h>
Output:
#include <conio.h>
Multiplication Tables from 2 to 6
int main()
2*1=2
{
2*2=4
int i,j, n=6;
2*3=6
printf(“ Multiplication Tables from 2 to 6\n”);
2*4=8
for (i=2;i<=n; i++)
2 * 5 = 10
{
2 * 6 = 12
for (j=1;j<=10;j++)
2 * 7 = 14
printf(“%d*%d=%d\t\n”,i,j,i*j);
2 * 8 = 16
}
2 * 9 = 18
printf(“\n”);
2 * 10 = 20
getch();
} 3*1=3
3*2=6
3*3=9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
~ 22 ~ 3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
/ Activity 4.3**********************************************************************
Write a program that takes as input the marks obtained in matriculation by 30 students of a class. The
program should display the average marks of the class.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> Output:
int main() Enter Obtained Marks of 30 Students:505
{ 405
int marks[30], total=0; 250
float avg; 475
printf(“Enter Obtained Marks of 30 Students:”); 450
for (int i=0; i<=30; i++) 415
{ 418
scanf(“%d”,&marks[i]); 246.
total=total+marks[i]; .
} .
avg= total/30; .
printf(“The Average of 30 Student is %.2f,avg); .
getch(); The Average of 30 Student is: 602.00
}
~ 23 ~
/ Exercise 1**********************************************************************
Use loops to print the following patterns on console.
a)
*****
*****
*****
b)
A
BC
DEF
GHIJ
KLMNO
***********************************************************************************/
#include <stdio.h>
#include <conio.h> Output:
int main()
*****
{ *****
for (int i=0; i<3; i ++) *****
{
for (int j=0; j<5; j ++)
printf(“*”);
printf(“\n”);
}
getch();
}
*******************************************************************************
#include <stdio.h>
#include <conio.h> Output:
int main() A
{ BC
Char ch=’A’;
DEF
for (int j =1; j <=5; j ++) GHIJ
{ KLMNO
for (int i =1; i<=j; i ++)
{
printf(“%c”,ch++);
}
printf(“\n”);
}
getch();
}
~ 24 ~
/ Exercise 4**********************************************************************
Write a program that takes two positive integers a and b as input and displays the value of a b.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> Output:
int main()
Please Enter the Value of A: 2
{
Please Enter the Value of A: 3
int a, b, sum=1;
printf(“Please Enter the Value of A:”);
The Answer of A power B is: 8
scanf(“%d”,&a);
printf(“Please Enter the Value of B:”);
scanf(“%d”,&b);
~ 25 ~
/ Exercise 4**********************************************************************
Write a program to display factroials number from 1 to 7. (Hint: Use Nested Loop)
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
Output:
int main()
The factorial of 1: is 1
{
The factorial of 2: is 2
int j, factorial=1;
The factorial of 3: is 12
for (int i =1; i<=7; i++)
The factorial of 4: is 72
{
The factorial of 5: is 480
for (j=1; j<=i; j++)
The factorial of 6: is 3600
{
The factorial of 7: is 30240
factorial= factorial*j;
}
printf(“The factorial of %d: is %d\n”, i , factorial);
factorial=i;
}
getch();
}
~ 26 ~
/ Exercise 4**********************************************************************
Write a program that takes 10 numbers as input in an array and displays the product of first and last
element on console.
***********************************************************************************/
#include <stdio.h>
int main() Output:
{ Please Enter 1/10 Number:1
int numbers[9]; Please Enter 2/10 Number:2
for (int i=0; i<10; i++) Please Enter 3/10 Number:3
{ Please Enter 4/10 Number:4
printf(“Please Enter %d/10 Numbers:”,i+1); Please Enter 5/10 Number:5
scanf(“%d”,&numbers[i]); Please Enter 6/10 Number:6
} Please Enter 7/10 Number:7
Please Enter 8/10 Number:8
Please Enter 9/10 Number:9
Please Enter 10/10 Number:10
The product of First and Last Number is :10
/ Exercise 4**********************************************************************
Write a program that declares and initializes an array of 7 elements and tells how many elements in
the array are greater than 10.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int main()
{ Output:
int count=0, numbers[6]={4,8,11,15,19,2}; The elements in the array Greater than 10 are: 3
~ 27 ~
COMPUTER SCIENCE UNIT 5
/ Exercise 1**********************************************************************
Write a function int square (int x); to calculate the square of an integer x.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
int square (int x)
{ Output:
return x*x; Please Enter Number to calculate Square:5
}
Square of 5 is: 25
int main()
{
int number;
printf(“Please Enter Number to calculate Square:”);
scanf(“%d”,&number);
printf(“Square of %d is: %d”, number, square (number));
getch();
}
~ 28 ~
/ Exercise 2**********************************************************************
Write a function int power (int x, int y); to calculate and return x y.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> Output:
Int power (int x, int y) Please Enter the value of X:5
{ Please Enter the value of Y:3
int i, result =1;
if (y == 0) X the power of Y is:125
return 1;
for ( i=1; i <=y; i++)
result = result *x ;
return result;
}
int main()
{
int num1,num2;
printf(“Please Enter the value of X:”);
scanf(“%d”,&num1);
printf(“Please Enter the value of Y:”);
scanf(“%d”,&num2);
~ 29 ~
/ Exercise 3**********************************************************************
Write a function to calculate factorial of a number .
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
Output:
int factorial (int x)
Please enter a number to calculate Factorial:6
{
The factorial of 6: is 720
int sum =1;
for (int i =1; i <=x; i++)
sum = sum*i;
return sum;
}
int main()
{
int fact;
printf(“Please enter a number to calculate Factorial:”);
scanf(“%d”, &fact);
printf(“The factorial of %d: is %d”, fact , factorial(fact));
getch();
}
~ 30 ~
/ Exercise 4**********************************************************************
Write a function which takes values for three angles of a triangle and prints whether the given values
make a valid triangle or not. A valid triangle is the one where the sum of three angles is equal to 180.
***********************************************************************************/
#include <stdio.h>
#include <conio.h> Output:
int triangle (int x, int y, int z) Please Enter First angle of the Triangle:60
{ Please Enter Second angle of the Triangle:60
int sum = x + y + z; Please Enter Third angle of the Triangle:60
if ( sum== 180 && x> 0 && y >0 && z >0) This is a valid Triangle
printf(“This is a valid Triangle”);
else
printf(“This is NOT a valid Triangle”);
}
int main()
{
int firstangle, secondangle, thirdangle ;
printf(“Please Enter First angle of the Triangle:”);
scanf (“%d”, &firstangle);
printf(“Please Enter Second angle of the Triangle:”);
scanf (“%d”, &secondangle);
printf(“Please Enter Third angle of the Triangle:”);
scanf (“%d”, &thirdangle);
~ 31 ~
/ Exercise 5**********************************************************************
Write a function which takes the amount and the interest percentage and return the interest amount.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
Output:
float calculateInterest (float x, float y) Please Enter the Amount:11001
{ Please Enter the Interest Percentage:5
float interest= y/100*x; Your Interest Amount is:550.049988
return interest;
}
int main()
{
float amount, interestPersentage;
printf(“Please Enter the Amount:”);
scanf(“%f”, &amount);
printf(“Please Enter the Interest Percentage:”);
scanf(“%f”, & interestPersentage);
~ 32 ~
/ Exercise 6**********************************************************************
Write a function which takes a number as input and display its digits with spaces in between.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
getch();
}
~ 33 ~
/ Exercise 7**********************************************************************
Write a function to print the table of a number.
***********************************************************************************/
#include <stdio.h>
#include <conio.h>
Output:
void printTable (int x)
{ Please enter a Number to print Table:3
3*1=3
for (int I = 1; i<= 10; i++)
3*2=6
printf(“ %d 8 %d = %d\n” , x,i,i*x);
3*3=9
} 3 * 4 = 12
3 * 5 = 15
int main() 3 * 6 = 18
{ 3 * 7 = 21
int number; 3 * 8 = 24
printf(“Please enter a Number to print Table:”); 3 * 9 = 27
scanf(“%d”,&number); 3 * 10 = 30
printTable(number);
getch();
}
~ 34 ~