Tuesday, 1 January 2019

LAB ACTIVITY 9 : Array

Exercise 

1. Write a program which reads 10 integer numbers into an array and display each of the value inside the array. Then execute the following process:

a.  Multiplication between 3rd and 7th input numbers.

b.  Summation of 2nd, 4th, 8th and 10th input numbers.

c.  5th input number to the power of 3.

d.  9th input number divide by 1st input number.






2. Table below shows the weekly production of KerepekKu Factory for the month of November 2012.


Based on the data above, write a complete C program with the implementation of array to 
carry out the following task:

a)  Display the grand total of chips production for the given month.

b)  Display the total production for each type of chip for the given month.

c)  Display the average of weekly production for each type of chip. 



Sunday, 2 December 2018

LAB 8 : Functions


Exercise

1. Based on the function definition below, write a complete C program with the implementation of functions: 

a)





     b)
    



2. Write a complete C program with the implementation of functions to generate a multiplication table based on user input. The output is displayed as below.





3) Write a complete C program to calculate total pay which includes net salary and bonus.
Listed below are functions that need to be included in your program.:

int BasicSalary() –  Ask user to enter basic salary.

int EPF(double) –  To calculate the amount of employees evident fund (EPF) deduction from basic salary.

int CalculateBonus(double) – To calculate the amount of bonus. Assume bonus is half of basic salary.

double DisplayTotalPay(double,double) – To calculate the total pay after EPF deduction and bonus reward.

Your program output should be like below:

Please enter your salary:
1200
Please enter the percentage of EPF deduction:
11
Your EPF deduction is RM132.00
Your bonus (half of salary) is RM600.00
Your total pay is RM1200.00 – RM132.00 + RM600.00 = RM1668.00 








Saturday, 17 November 2018

LAB ACTIVITY 7 : Repetition Structure


Exercise 

a)  Create a program to generate a multiplication table by using while loop. The multiply is determined based on user input. Your output should be like below:

     Output:
     Please enter multiplication table: 3

     3 Times Table

     1 * 3 = 3
     2 * 3 = 6
     ..
     ..
     12 * 3 = 36




b)   Calculate the total of any five numbers using do … while loop.Your output should be like below:

      Output:
      Please enter number 1: 2
      Please enter number 2:  3
      Please enter number 3:  1
      Please enter number 4:  4
      Please enter number 5:  5

      The total of five numbers is 15




c)   Write a program for the following problem by using for statement:
Ahmad saves RM1000 in his account in a bank which returns 5% of annual interest. Assuming that all interests is left deposited in his account, calculate and print the amount of money in his account at the end of each year for 10 years by using for loop.









LAB ACTIVITY 6 : Control Structure

Exercise :

a) Write a program using if … else statement to display student’s bachelor class of graduation based on Cumulative Grade Point Average (CGPA) by referring to the table below.





b) Write an interactive program that contains if … else statement to calculate the area of a rectangle OR triangle OR circle. The selection depends on the character entered by the user -R/r for rectangle and T/t for triangle and C/c for circle. You may use the following equation:

area of rectangle = width × length

area of triangle = 12× base × height

area of circle = 3.142 × radius2





c) Modify the program in (b) by using switch … case statement. 

 




Thursday, 25 October 2018

LAB ACTIVITY 5: Arithmatic Expression and Operators

a. Convert these mathematical expression into C expression

  1.  y = m*x +c
  2. (2*a) / b * 3 *c
  3. 9*p + 2*q ( r + 2 ) / 2*(s -1)
  4. ( (3*e - d) / (x - 9) ) - ( (4 - pow (c,3)) / 4*y )

b. Determine the order of solving the expressions below and calculate the value of x.
  1. x = 15
  2. x = 3
  3. x = 108
  4. x = 1

c. Given the value of num1=26. Determine the value of num2 after the execution for each of
the following statement.

  1.  24
  2.  26
  3.  24
  4. 27
d. Assume i, j and k are integer variables with i=3 and j=4. Determine the value of k for
each of the following statement. (Assume that each of the operation is non-contiguous)

  1. k = j++;
       = 4
  2. k = ++j;
       = 5
  3. k = ++i * j--;
       = 5*4
       = 20
  4. k = j++ * --i;
       = 4*2
       = 8
  5. k = j * i/j--;
       = 4* 3/4
       = 3
  6. k = 24/j++ - 16 % i;
       = 24/4 - 16 % 3
       = 6 - 1
       = 5
e.   Determine the output of the program below

  

      Output :

      1: 10
      2: 10
      3: 11
      4: 11
      5: 11
      6: 31
      7: -11
      8: 32
      9: 32
    10: 32
    11: 0
    12: 1
    13: 0


f.  Given i=2, j=5.

i)  Output: 7
ii) Output: 8
iii) Output: 9
iv) Output: 12
v)  Output: 36