You are on page 1of 3

Sheet # 3

1) Find the value of x for each of the following program segments


a) Program segment 1
int x=2;
if (x>=0)
x++;
else if(x>=1)
x+=10;
cout<<x;
b) Program segment 2
int x=2;
if (x>=0)
x++;
if(x>=1)
x+=10;
cout<<x;
2) What will be the value of x when y=12.0
a) float x=25.0,y;
scanf(“%d”,&y);

if (y!=(x-10.0))
x=x-10.0;
else
x=x/2.0;
cout<<x;
3) Write a program that reads n integer and determines whether it is even or odd.
4) What will be the value of y after the following switch statement is executed?
x=3;
switch(x+3)
{
case 6: y=1;

default: y+=1;

}
5) Use a switch statement to rewrite the following if statement
if(a==1)

x+=5;

else if(a==2)

x+=10;
else if(a==3)

x+=16;

else if(a==4)

x+=34;
6) You have just started a sales job in a department store. Your salary consists of a
base salary and a commission. The base salary is $5,000. The following scheme is
used to determine the commission rate:

Sales Amount Commission Rate


$1-$5,000 8%
$5,001-$10,000 10 %
$10,001 and above 12 %

Write a program that reads the amount of your sales and computes your salary.

7) Write a nested if statement to display a message that indicates the educational level
of a student based on his or her number of schooling:
0-none

1 through 6-Elementary School

7 through 9-Middle School

10 through 12-High School

>12- College.

Print a message to indicate invalid data as well.


8) Write a C program read the student score and display the corresponding grade
according to the following table:

Score (x) Grade

85<=x<=100 A

75<=x< 85 B

65<=x< 75 C

50<=x< 65 D

x<50 F

You might also like