You are on page 1of 5

Declare an integer array called num have 3 rows and 5 columns, and assigns the data below into

the array elements.

10 11 12 13 14
20 21 22 23 24
30 31 32 33 34

Using C language, write the statement (code) to:-


i. Floating point variable called tax per year and assign 133.50 to the variable.
ii. A character variable called grade and assign z to the variable
iii. A function called calculates did not return any value. The function have 2 integer arguments
called x and y.

Draw a flowchart based on the requirements given below:


i. Ask user to enter the integer value and assign the input to variable temp
ii. Based on the value of temp the program will display the message as below:
• WEAK if the value of temp is less than 19
• GOOD if the value of temp is between 20 to 40
• EXCELLENT if the value of temp is more than 41
iii. Ask user do you want continue press 1, if user press 1 repeat step i

a. Write an appropriate selection statement based on the table 1 below. The selection of grade
based on the input of mark.

Mark Grade
89.5-100 A
74.5-89.4 B
64.5-74.4 C
< 64.4 F

Table 1

Draw a flowchart based on the requirements below:


i. Display the menu as below:
1.Circle
2.Rectangle
ii. Accept input menu from user
iii. If user choose menu 1 calculate area and perimeter of circle
iv. Else if user choose menu 2 calculate area and perimeter of rectangle
v. Display the result
vi. Ask user do you want continue if user choose Y repeat step i

A C program contains the following declaration and initial assignments:


int i = 4, j= 9,k;
float x=0.002,y=-0.03,z;
char a,b,c=’A’,d=’E’;
Determine the value of each of the following assignment expressions. Use the values
originally assigned to the variables for each expression.
i. k=(i+j)
ii. i=j
iii. z=(i/j)
iv. i=j=1.1
v. x*=2
Convert the following program from switch statement to if ..else statement
main()
{
switch(in)
{
case ‘x’:
printf("Kuala Lumpur");
break;
case ‘y’:
printf("Penang”);
break;
case ‘z’:
printf("Johor");
break;
default:
printf("enter only x , y or z"):
break;
}
}

Write a program using for and while loop to generate the following outputs
Write a program base on the pseudocode given below. Your program must use string function such as
strlen,strcpy and strcat.
Begin
Display Please enter username
Accepts username
Display Please enter password
Accepts password
Display length for username
Display length for password
Identify the username similar with “Default”
• If similar
o Indentify the password similar with “123456”
▪ If similar display “Authorize User”
• Else display “Unauthorized user”
End

You are required to write a program to calculate the marks and give the grade based on the table below and print the
result slip for each student. This program should have a main() function, grade() function , average() function and a
display() function. All functions must be called from the main() function. You are required to use if..else statements
for this question.

Grade table

Marks Grade
80<=marks<=100 A
70<=marks<=79 B
65<=marks<=69 B-
60<=marks<=64 C
Marks>59 F
The screen shot of the program is as below

Write a program that request the user to enter eight numbers. The program will then determine whether the numbers
entered can be divided by 3 or not. The program must be able to keep a list for those numbers that can be divided by
3 and another list for those numbers that cannot be divided by 3. You have to use arrays to help you keep a list of
numbers. Finally display which numbers that can be divided by 3 and which numbers that cannot be divided by 3

Enter Number 1: 8
Enter Number 2: 15
Enter Number 3: 5
Enter Number 4: 3
Enter Number 5: 9
Enter Number 6: 13
Enter Number 7: 12
Enter Number 8: 18

These are the number can be divide by 3: 15 3 9 12 18


These are the number that cannot divide by 3: 8 5 13

5 number can be divide by 3


3 numbers cannot be divide by 3

Press any key to continue..

a. Write a program based on the user requirements below:


In the main() function :
▪ Display a menu and ask the user to key in their destination.
▪ Ask user to key in the quantity.
▪ Call function get_price(..) and pass the destination value to get the destination price
and return the price to main.
▪ Call function calculate(..) and pass both value of quantity and price to calculate total
pay, return the total pay to main.
▪ Call function print_bill(…) and pass the value of destination , quantity , total pay and
display all the information as shown in figure 1
▪ Display a menu and ask the user to key in their destination.
▪ Ask user to key in the quantity.
▪ Call function get_price(..) and pass the destination value to get the destination price
and return the price to main.
In function get_price(..) :
▪ Return the price of the destination to main() function.
▪ Use if..else statement in this function.
i. In function calculate(..) :
▪ Return the total payment to main() function.
ii. In function print_bill(…)
▪ Display the destination quantity and total payment.
▪ Ask user “do you want continue” if user press 1 call main() function ,if user press 0 exit program.
▪ Display the destination quantity and total payment.
i. The output design is shown in figure 1.

Destination

Destination 1: Langkawi RM 100.00 per night


Destination 2: Phuket RM 180.00 per night
Destination 3: Pangkor RM 80.00 per night

Enter Destination :1
Enter quantity :3
Bill

Destination :1
Price :RM 100.00
Quantity :3
Payment :RM 300.00

You might also like