Professional Documents
Culture Documents
Revision: Malaysian Institute of Aviation Technology
Revision: Malaysian Institute of Aviation Technology
Revision
Malaysian Institute of Aviation Technology
Exercise 1
You are having dinner at a restaurant and there is
the promotion at the restaurant. If your bill is more
or equal to RM250, you are entitle for:
a) If your age is 40 and above, 20% discount and
further 20% reduction if you are female.
b) If your age is below 40, 10% discount and
further 10% discount if you are male.
Prompt user to enter their bill amount.
Malaysian Institute of Aviation Technology
#include <stdio.h>
else {
newbill = bill * 0.9;
if(gender == 1){
newbill = newbill * 0.9;
printf("your bill after discount: %0.2f", newbill);
} else {
printf("your bill after discount: %0.2f", newbill);
}
}
} else {
printf("You are not eligible for discount");
}
return 0;
}
Malaysian Institute of Aviation Technology
Exercise 2
Calculate the volume of cylinder using formula:
C = πr2h
π = 3.142
Value of r and h have to be entered by user.
r
Malaysian Institute of Aviation Technology
#include<stdio.h>
#define PI 3.142
int main ()
{
return 0;
}
Malaysian Institute of Aviation Technology
Exercise 3
Write a program where user have to enter their
weight. The program then will print:
• Weight <= 45kg Skinny
• 46 < Weight < 60 Ideal
• Weight >= 60 fat
Malaysian Institute of Aviation Technology
#include<stdio.h>
int main ()
{
int weight;
return 0;
}
Malaysian Institute of Aviation Technology
Exercise 4
Write a program using for loop that will give the
following output:
4
1
-2
-5
-8
-11
-14
Malaysian Institute of Aviation Technology
#include<stdio.h>
int main ()
{
int a = 7;
for(int i = 0; i<7; i++){
a = a-3;
printf ("%d \n", a);
}
return 0;
}
Malaysian Institute of Aviation Technology
#include<stdio.h>
int main ()
{
int a = 7;
int count= 0;
while(count < 7){
a = a-3;
printf ("%d \n", a);
++count;
}
return 0;