Sie sind auf Seite 1von 8

Question 1

a) Write a command to compile a C program and execute the file at terminal in Linux Ubuntu
#include <stdio.h>
int main ( )
printf(“Hello World\n”);
return 0;

b) Write a statement to declare variable

i. x as floating data type. [2Marks]

float x ;

ii. y as integer data type. [2Marks]

int y ;

iii. z as character data type. [2Marks]

char z ;
Question 2

a) Write a C program to receive input (integer number) from user and store in variable x. Then
display the stored number at terminal(black screen). [12Marks]

Example output display:

Please enter your choice of number: 15

You have entered: 15

#include <stdio.h>
int main ( )
float x;
printf(“Please enter your choice of number:”);
printf(“You have entered: %2.f”,x);
return 0;

Question 3

You are required by your client to build a C program to calculate perimeter and area of a right
triangle. The client wants you to define all input variables as integer. Then, user must input the
base(b) and height(a) of the triangle.
Given formula is:

Area= 0.5*(a)*(b)

Perimeter = a + b +

a) Write pseudo code for the above mentioned program.

2.Input_base and height
3.Calculate area and perimeter
4.Output_value area and perimeter

b) Draw flowchart for the above mentioned program.



Input base and height

Calculate area and perimeter

Output value of area and


c) Write C program and the output is as shown in example below.

Example output display:

Enter height (a) in cm: 10

Enter base (b) in cm: 20
The perimeter of triangle is: 52.36 cm
The area of triangle is: 100 cm2

*hint: Please include math library (math.h)

Use function pow(base value, power of value) for power.
Use function sqrt(value) for square root.

int main ()
{int a,b ;
float area,perimeter;
printf("Enter height in cm:");
printf("Enter base in cm:");
printf("\nThe area of triangle is (cm2): %.2f",area);
printf("\nThe perimeter of triangle is (cm): %.2f",perimeter);
return 0;
Question 4
Write a C program to calculate sum and average of electricity bills charge. Then the average of the
bill charge determines the status usage consumption of the electricity. User is required to provide
numbers of month to calculate and followed by the electricity charge of the months. In summary,
Table 2 shows the relation of average bill charge and usage consumption status.

Table 2
Average Bill Charge (RM) Usage Consumption
0.00 – 39.99 LOW
40.00 – 109.99 MEDIUM

Example output.
***T&B care-system***
Please enter the bill account number: 12345
Please enter number of months: 3
Please enter amount for month 1(RM): 32.30
Please enter amount for month 2(RM): 27.70
Please enter amount for month 3(RM): 40.00

Account number is 12345.

The sum of bills electricity charge for 3 month is RM 100.00. The
average of bills electricity charge is Rm33.33
Your electricity usage is LOW

Please use for-loop and if-else statement

a) Write down pseudo code of the program. [10 marks]

2.Input_ bill account number
3.Input _ number of month
4.Input _ the amount for each month
5.Calculate sum and average of electricity usage
6.Determine the level usage consumption
7.Output _ sum and average of bills electricity
8.Output _ level of usage consumption
b) Draw flowchart for the program. [10 marks]


Input_ bill account number, number of month and a = 1

False Input_ amount of electricity charge in

a < = number of each month


print a++ Sum=sum of every amount of

electricity charge in each month
Average = sum/number of month


Output_ Sum and average bills electricity charge

Usage Consumption = if average

<=39.99, print _” Your electricity
Output_ account number , sum of bills usage is LOW";
,average of bills and usage else if ((average >=40.00) &&
consumption (average <=109.99)), print_” Your
electricity usage is MEDIUM";
else if (average >=110.00,
print_”Your electricity usage is
c) Write a complete C program to accomplish the program [20 marks]

#include <stdio.h>
int main()
int ban,a;
float mnth,average,sum=0,number;
printf("\n******T&B Care-System******");

printf("\n\nPlease enter the bill account number:");

printf("Please enter number of months:");

for (a=1; a<=mnth; a++)

printf("Please enter amount for month %i(RM):",a);
sum =sum + number;
average = ((sum)/(mnth));
printf("\n\nAccount number is:%i", ban);
printf("\nThe sum of bills electricity charge for the amount of month entered is :

printf("\nThe average of bills electricity charge is : Rm%.2f",average);

if (average <=39.99)
printf("\nYour electricity usage is LOW");
else if((average >=40.00) && (average <=109.99))
printf("\nYour electricity usage is MEDIUM");
else if(average >=110.00)
printf("\nYour electricity usage is HIGH");
return 0;

*DUE DATE : 7/8/2019 (12.00PM)