You are on page 1of 6

(Computer 10th) USER INTERACTION (E-Series) 53

Solution of Act1v1t1es

Activity 2.1
Write down the output of following code:
#include<stdio.h>
void main()
{
printf("I am UPPERCASE and this Is lowercase");

Output
I am UPPERCASE but this is lowercase

Activity 2.2
Write a program that shows your first name in Uppercase a
on screen.
#includa<stdio.h>

int main()
{
clrscr();
printf("Pakistan");

Output
Pakistan
(Computer 10th} USER INTERACTION (E-Series) 54
l'.ctlvlty 2.3
Write a program that takes roll number, percentage of marks and grade from user as input
Program should display the formatted output like following:
Roll no input value
Percentage input value %
Grade input value
#include<stdio.h>

Int main()
{

int roll_numbar;
float parcantaga;
char grada;
printf("Please enter your Roll Number: ");
scanf("%d",&roll_number);
printf("Please enter your Percentage: ");
scanf("%f ",&percentage);
printf("Please enter your Grade: ");
scanf(" %c", &grade); // All use SPACE bef
printf("Roll no It It It It %d ln",roll_numb1
printf("Percentage 11:lt It %fln",per
printf("Grade It It : It It %c",grad

Output
Please enter your Roll
Please enter your,
Please enter your
Roll no (f 36
89.000000
Grade A
(Computer 10th) USER INTERACTION (E-Series) 55
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>

int main()
{
Int n;
printf("Enter any number: ");
scanf("%d",&n);
prlntf("lnArea of Square =%d",n*n);
getch();

Output
Enter any number: 6
Area of Square= 36

Activity 2.5 ·-... . �/


Write a program that takes as input the num . .s fn jar A and the numbers of balls in jar B.
The program calculates and displays the tot -� Yo! balls.
#include<stdio.h>

int main()
{.

int a,b,sum = 0;
printf("Enter n
scanf("%d",&.
printf("�te
scan!('°
sum =a+ .. .>
printf("Total Number of Balls = %d",sum);

Output
Enter number of balls in Jar A: 1 0
Enter number of balls in Jar B: 15
Total Number of Balls = 25
Easy Notes (Computer 10th) USER INTERACTION (E-Series) 56
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>

int main()
{

int op,dp;
prlntf("Enter Orlgnal Price of shirt ");
scanf("%d",&op);
prlnlf("Enter Discount in percentage");
scanf("%d",&dp);
prlntf("lnOrignal Price of shirt = %d",op);
printf(''lnDiscount on Shirt = %d",dp*op/100);
printf("lnPrice of shirt after discount = %d",op-dp);

Output
Enter Original Price of shirt 290
Enter Discount in percentage 10
Original Price of shirt= 290
Discount on Shirt= 29
Price of shirt after discount= 261

Activity 2.7
Write a program that takes mber from user, computes the product of both digits and
show the output.
#include<stdio.h>

int main()
{

int digit
printf("Please enter the first digit number: ");
scanf("%d",&digit1);
printf("Please enter the second digit number: ");
scanf("%d",&digit2);
prinlf("lnProduct of first and second digit is: %d", digit1*digit2);

Output
Please enter the first digit number: 6
Please enter the second digit number: 5
Product of first and second di it is: 30
(Computer 10th) USER INTERACTION (E-Series) 57
Activity 2.8
Write a program that takes seconds as input and calculates equivalent number of hours, minutes
and seconds.
#include<sldio. h>

int main()
{
float seconds, minutes, hours;
printf{"Please enter the seconds: ");
scanf(" %f ",&seconds);
minutes = seconds/ 60;
hours = minutes/ 60;
printf("lnTotal Seconds:%.2flnTotal Minutes: %.2f\nTotal Hours:%.

Output
Please enter the seconds: 234

Total Seconds: 234.00


Total Minutes: 3.90
Total Hours: 0.07

Activity 2.9
Convert the following algebraic
X = 6y + X
X = yz3 +3y
2
z=x+LA

Solution:
x=6•y+z
x= y •z•z•z+3• y
z=x+ y • y t3•x
z =(x-2) • (x-2)+3• y
y= ( x+3•z/2 )+z•z•z+x/z
/Computer 10th) USER INTERACTION (E-Series) 58
Activity 2.10
Consider the variables x= 3, y
= 7. Find out the Boolean result of following expressions.

(2 + 5) > y (x+4) == y
X != (y-4) (y/ 2) >= X
1- <x (x*3)<= 20
Solution:
(2 + 5) > y False (x+4) == Y True
XI= (y-4) False (y /2) >• X True
-1 < x True (X* 3) <• 20 True

Activity 2.11
Assume the following variable values x=4, y
= 7, z=8. Find out the res

x == 2 llv == B 7> = y&&z<5 ·


z >= 5II x<= 3- y== 7 &&!(true)
x ! = yII y< 5 l(z>x)
Solution: .
x == 2 11y== 8 False ,;·¥:&&z<5 True
z >= 511x <= -3 True ='{&&!(true) False
x!=y II y< 5 True l(z>x) False

= 2
=4
9
=4
= 32
= 2

You might also like