Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

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>

int main (){


float bill, newbill;
int age, gender;
printf("Please enter your bill \n");
scanf("%f", &bill);
printf("please enter your age \n");
scanf("%d", &age);
printf("Please enter your gender (1=male, 2=female)\n");
scanf("%d", &gender);
if (bill >= 250){
if(age >= 40){
newbill = bill * 0.8;
if(gender == 2){
newbill = newbill * 0.8;
printf("your bill after discount: %0.2f", newbill);
} else {
printf("your bill after discount: %0.2f", newbill);
}
}
Malaysian Institute of Aviation Technology

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 ()
{

int height, radius;


float volume;

//enter the height //


printf("Enter the value of h \n");
scanf("%d", &height);

//enter the radius //


printf("Enter the value of r \n");
scanf("%d", &radius);

// calculate the volume of cylinder//


volume = PI * height * (radius * radius) ;
printf ("Volume of cylinder : %0.2f \n", volume);

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;

//enter the weight //


printf("Enter your weight \n");
scanf("%d", &weight);

if(weight <= 45){


printf("you are skinny");
}else if(weight > 45 && weight <= 60){
printf("you are ideal");
}else{
printf("you are fat");
}

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;

You might also like