Professional Documents
Culture Documents
MARITIME TRANSPORT
Sheet # 4
Note: In all the following questions, please show all your work if possible.
b) Program segment 2
int x=2;
if (x>=0)
x++;
if(x>=1)
x+=10;
printf(“%d”,x);
if (y!=(x-10.0))
x=x-10.0;
else
x=x/2.0;
printf(“x=%f,y=%f\n”,x,y);
Page 1 of 5
12 March 2012
b) float x=25.0,y;
scanf(“%d”,&y);
if (y<12.0)
if(y>=0.0)
x=5*y;
else
x=2*y;
else
x=3*y;
printf(“x=%f,y=%f\n”,x,y);
3) Write a program that reads an 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;
x+=5;
else if(a==2)
x+=10;
Page 2 of 5
12 March 2012
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:
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
>12- College.
Page 3 of 5
12 March 2012
8) Write a program that determines the state tax owed by an employee. The state
charges a 4% tax on net income. Determine net income by subtracting a $500
allowance for each dependent from gross income. Your program will read gross
income, and number of dependents. It will then compute the actual tax owed and
print this value on the screen.
9) Develop a C program that will determine if a department store customer has exceeded
the credit limit on a charge account. For each customer, the following facts are
available:
Account number
Balance at the beginning of the month
Total of all items charged by this customer this month
Total of all credits applied to this customer’s account this month
Allowed credit limit
The program should input each of these facts, calculate the New balance
(=beginning balance + charges – credit), and determine if the new balance exceeds
the customer’s credit limit. For those customers whose credit limit is exceeded, the
program should display the customer’s account number, credit limit, new balance,
and the message ‘Credit limit exceeded’. The program should perform this
calculation for one customer only.
10) Write a program that may be used to convert either from entered distance in miles
to kilometers or from entered distance in kilometers to miles (1 mile=1.5 kilometers)
after prompting the user to type the first character of the unit of the measured
distance (K or M). Enter the distance according to the entered unit.
11) Write a program that takes two integers and displays their minimum.
12) Write a program that may be used to compute the area of a square (area=side2) or
a triangle (area=0.5*base*height) after prompting the user to type the first character
of the figure name (S or T). Enter required data according to the figure being handled.
Page 4 of 5
12 March 2012
13) Write a C program read the student score and display the corresponding grade
according to the following table:
85<=x<=100 A
75<=x< 85 B
65<=x< 75 C
50<=x< 65 D
x<50 F
Page 5 of 5
12 March 2012