0% found this document useful (0 votes)
56 views10 pages

Page 10th Computer Ch-2 Exercise Half

Uploaded by

Ali Raza
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)
56 views10 pages

Page 10th Computer Ch-2 Exercise Half

Uploaded by

Ali Raza
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/ 10

(Computer 10th} USER INTERACTION (E-Series) 43

Q.1 Multiple Choice Questions.


i#§HMI
Sr.
Question A B C D
No
print! Is used to print_ type of data. int float char All of these
scanf is a __ in C programming none of
2 Keyword Library Function
language. these
getch() Is used to take __ as Input
3 Int float char All of th ese
from user. /4- ------1
- - o::- -::- -- --11
----= - .,. - -, ,... - -: - .,.. -:::-t -:-- - +-
- -:-in_g _ pa - - --
- +--
1- +:-Let'"'th
-,
'"ei llow rt of code , what w ll be
4 th e value of variable a after execution: 8.8 8 8.2
Int a= 4; float b=2.2; a= i • b;
Which of the following is a valid line of none of
5 int=20;
code? these
Which operator has highest precedence
6
among the following:
Which of the following is not a type of Logical
7
operator: operator operator
The operator % is used to
8 Factorial Square
Which of the following •a· None of
9 '9'
character. these
keywords
All logical
can be
case operators None of
10 used as
sensitive are binary these
variable
language operators
names
KEY:
4 5 6 7 8 9 10
D B B D B B C D
Q.2 True or Fafae·
1. Maximum value that can be stored by an integer is 32000. T/F
2. Format specifiers begin with a % sign. T/F
3. Precedence of division operator is greater than multiplication operator. T/F
4. getch is used to take all types of data input from user. T/F
5. scanf is used for output operations. T/F
Key:
2 3 4 5
T F T F
{Computer 10th} USER INTERACTION (E-Series) 44
Q.3 Define the following:
1) Statement Terminator See Page No. 33
2) Format Specifier See Page No. 29
3) Escape Sequence See Page No. 33
4) scan! See Page No. 31
5) Modulus Operator See Page No. 38

Q.4 Briefly answer the following questions.


1) What Is the difference between scanf and getch? See Page No. 69
2) What function of C language Is used to display output on screen? See Page No. 29
3) Why format specifiers are important to be specified In 1/0 operations? See Page No. 29
4) What are escape sequences? Why do we need them? See Page No. 33
5) Which operators are used for arithmetic operations? See Page No. 36
6) What are relational operators? Describe with an example. See Page No. 39
7) What are logical operators? Describe with an example. See Page No. 40
I
8) What is the difference between unary operators and blna See Page No. 41
9) What Is the difference between == operator and = See Page No. 40
10) What Is meant by precedence of oper, See Page No. 42
has the highest precedence in C la

Q.5

a) #include<stdio, h>
Output:
void main() 0,7,9
{
int x = 2, y = 3, z = 6;
int ans1 , ans2 ,ans3;
ans1 = x / z * y;
ans2 = y + z / y * 2;
ans3 = z / x + x * y;
printf('%d %d %d' , ans1 , ans2 , ans3);

b) #include<stdio,h>
Output:
void main() nn
{
printf('nn lnln nnn Inn Int It"); nnn
printf("nn /n/n nn/n\n"); n
t nn /n/n nn/n
(Computer 10th) USER INTERACT/ON (E-Series) 45
c) #include<stdio.h> Output:
void main() 9
{
int a =4, b;
float c = 2.3;
b = c * a;
printf("%d", b);

d) #include<stdio. h>
void main()
{
int a = 4 • 3 / ( 5 + 1 ) + 7 % 4;
printf("%d", a);
}
e) #include<stdio.h>
void main()
{

Q.6 Identify errors in the following code segme


a) #include<stdio.h>
Error:
void main() Value of variable a is not
{ initialized.
Inverted comma is missing after %d

b)
Error:
Semicolon is m1ss1ng after int
variable. Invalid syntax of a + b = c;
; b, c, The correct syntax Is c=a+b;
tf("Enter First Number:');
-·scanf("%d", &a);
printf("Enter second number:');
scanf("%d', &b);
a + b = c;
}
c) #include<stdio.h>
Error:
void main() Double quotes missing in printf
{ statement and } has extra ;
int num;
printf(Enter Number:");
scanf(%d, &num);
};
/Computer 10th) USER INTERACTION (E-Series) 46
d) #include<stdio.h>
Error:
void main()
Square bracket is used instead of
{ parentheses. In printf statement float variable
float f; is used with %f in scant instead of %c.
printf['Enter value:");
scanf('%c", &f);

Programrrnng Exercises
Exercise 1
The criteria for calculation of wages in a company are given below:
Basic Salary = Pay Rate Per Hour X Working Hours of Employ
Overtime Salary = Overtime Pay Rate X Overtime Hours of Emp ...
Total Salary = Basic Salary + Overtime Salary

Write a program that should take working hours and overtime h9


.
program should calculate and display the total salary of employe
Program
#include<stdio.h>

void main()
{
int wh,oh,rate_per_hour,oJi:
printf("Enter Working Ho
scanf("%d",&wh); /4
printf("Enter ove
scanf("%d",&o
printf("Enter urs:");
jler_hour);
Time rate per hour:");
citrate);
ry = wh*rete_per_hour;
_salary = oh*otrate;
.. _salary = basic_salary+overtlme_salary;
printf("Total salary is= %d",total_salary);

Output
Enter Working Hours of Employ: 20
Enter overtime working hours: 10
Enter rate per hours: 20
Enter over Time rate per hour: 1 O
Total Salary is = 500
(Computer 10th) USER INTERACTION (E-Series) 47
Exercise 2
Write a program that takes Celsius temperature as input, converts the temperature into
Fahrenheit and shows the output Formula for conversion of temperature from Celsius to
Fahrenheit is:

F=2.C+32
5
Program
#include<stdio.h>

int main()

float celsius, fahrenheit;


printf("Enter temperature in Celsius: ");
scanf("%f ", &celsius);
//celsius to fahrenheit conversion formula
fahrenheit = (celsius • 9 / 5) + 32;
printf("Celsius =%.2f Fahrenheit=%.2f ", cels·i us,
fah

Output
Enter temperature in Celsius: 37
Celsius = 37.00 Fahrenheit = 98.60

Exercise 3

. .
Write program that display the foll

2
Program
#Include <sldlo.h>
Int main()
{

Output

2 3 4
(Computer 10th} Exercise USER INTERACTION (E-Series) 48
4
Write a program that displays the following output using single printf statement:
l am aBoy
I live in Pakistan
I am a Proud Pakistani
Program
#include <stdio.h>

int main()
{
printf("I am a boy In I live in Pakistan In I am a Proud Pakistani");

Output
I amBoy
I live in Pakistan·
I am a Proud Pakistani

Exercises
A clothing brand offers 15% discount on ea lady buys 5 shirts from this brand. Write a
program that calculates total price aft
Original prices of the shirts are:
Shirt1 = 432
Shirt2 = 320
(Computer 10th) USER INTERACTION (E-Serles) 49
Program
#include<stdio.h>

int main()
{

int shirt1 = 423. shirt2 = 320, shirt3 = 270, shirt4 = 680, shirts = 520;
float totalprice, totaldiscount, finalprice;
printf("First Shirt price: %d It I t Discount is %.2f It Payable price: %.2 f ln",shirt1, (shirt1*0.15),
(shirt1-(shirt1*0.15)));
printf("Second Shirt price: %d It Discount is %.21 It Payable ln",shirt2,
(shirt2*0.15), (shirt2-(shirt2*0.15)));
printf("Third Shirt price: %d It It Discountis %.21 It Payable price:
(shirt3-(shirt3*0.15)));
printf("Fourth Shirt price: %d It Discount is %.2f It Payable
(shirt4-(shirt4*0.15)));
printf("Fifth Shirt price: %d It It Discount is %.21 It P �: %.21 ln",shirt5, (shirtS*0.15),
··
(shirt5-(shirt5*0.15)));
printf("lnln----------�
, l',,l--------ln");
totalprice = shirt1 + shirt2 + shirt3 + shiry
totaldiscount = (shirt1*0.15)+(shirt2*001 3*0.15)+(shirt4*0.15)+(shirt5*0.15);
finalprice = (shirt1-(shirt1*0.15))+ *0.15l)+(shirt3-(shirt3*0.15))+(shirt4 -
(shirt4*0.15))+(shirt5-(shirt5*
printf("Total price: %.21 It T
totaldiscount, finalprice);

Output
First Shirt Price Discount is 63.45 Payable price: 359.55
Second Shi · / Discount is 48.00 Payable price: 272.00
Third Shirt P Discount is 40.50 Payable price: 329.50
Fourth Shirt Price-. > Discount is 102.00 Payable price: 578.00
Fifth Shirt Price Discount is 78.00 Payable price: 442.00

Total Price: 2213.00 Total Discount is 331.95 Final price: 1881.05


(Computer 10th) Exercise USER INTERACTION (E-Series) 50
6
Write a program that swaps the values of two integer variables without help of any third variable.
Program
#include<stdio.h>

int main()
{

int a=10, b= 20;


printf("Before swap a= %d b= %d",a,b);
a= a+b; //a= 30 (10+20)
b= a-b; //b= 10 (30-20)
a= a-b; //a= 20 (30-10)
printf("lnAfler SW<!p a=%d b=%d",a,b);

Output
Before swap a = 10 b = 20
After swap a = 20 b = 10

Exercise 7
Write a program that takes a 5 digit number a
last digit of number.
Program
#include<sldio.h>

int main()
{

~r·with length 5 digits:");


r>:
first and 5th digit is: %d", (number/ 10000) + (number %10));

Output
Enter a number with length 5 digits: 12345
The sum of first and 5th digit is: 6
(Computer 10th} Exercise USER INTERACTION (E-Series) 51
8
Write a program that takes mol)thly income and monthly expenses of the user like electricity bill,
gas bill and food expense. Program should calculate the following:
Total monthly expenses • Yearly saving
Totally yearly expenses Av!lrage saving per month
Monthly savings Average expense per month
Program
#include<stdio.h>

int main()

int monthly_income, electricity_bill, gas_bill, food_expense, monthly_


·
monthly_savings;
prinlf("Please enter your Monthly Income: ");
scanf("%d",&monthly_income);
printf("Please enter you Monthly Expenses: ");
printf("lnlnltYour Electricity Bill: ");
scanf("%d",&electricity_bill);
printf("ltYour Gas Bill: ");
scanf("%d",&gas_bill);
prinlf("IIYour Food Expense: ");
scanf("%d",&food_expense);
monthly_Expenses = electricity_bill + ga � /ill - v d_expense;
prinlf("lnlnlt Total Monthly Expense�· - ")monthly_Expenses);
·
prinlf("lnlt Total Yearly Expe monthly_Expenses)*12);
monthly_savings = monthly . . hly_Expenses;
prinlf("lnlnlt Your Monthly . %d", monthly_savings);
prinlf("lnlt Your Yearly • d", monthly_savings*12);
printf("lnlnltAverage month: %d", monthly_savings);
prinlf("lnltAve per month: %d", monthly_Expenses);

Output
Please enter '{I
Please enter your· thly Expenses
Your Electricity Bill 2300
Your Gas Bill 500
Your Food Expense 22000
Total Monthly Expenses are 24800
Total Yearly Expenses are 297600
Your Monthly Saving is 38200
Your Yearly Saving is 458400
Average saving per month 38200
Average expense per month 24800
{Computer 10th) Exercise USER INTERACTION (E-Series) 52
9
Write a program that takes a character and number of steps as input from user. Program should
then jump number of steps from that character.
Sample output:
Enter character: a
Enter steps: 2
Enter character: c
Pro ram
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
char c;
int steps;
printf("Enter character: ");
scanf("%c",&c);
printf("lnEnter steps: ");
scanf("%d",&steps);
int x = c + steps;
printf("lnNew Character. %c",x);
getch();

Out ut
Enter character: a
Enter steps: 2
New Character: c
Exercise 10
Write a program that takes radi
the area of circle.
Pro ram
#inciude<stdio.h>

int main()
;; •
{ clrs�:, �/
float!.��:-
printf("Please enter the radius of circle: ");
scanf(" %f ",&radius);
printf("ln Area of circle is: %.21 ", 3.14"radius•radius);
getch();

Out ut
Please enter the radius of circle: 20
Area of circle is: 1256.00

You might also like