BIC10204 ( ALGORITHMS )
LAB 2 - BIC10204
QUESTION 1(a, b, and c):
1. Identify what are the input, process, and output.
a. Find the mean of 4 numbers, P, Q, R, and S.
b. Convert a length of an object from millimeter to centimeter.
c. Calculate the volume of a cone, if the volume is below 12cm^3, print “Accepted” but if the volume is equal or more than 12cm^3, print “Not Accepted”.
IPO FOR QUESTION 1(a, b, and c):
a.
- Input: P, Q, R, S
- Process: Mean = (P+Q+R+S)/4
- Output: Mean of 4 numbers
- Input: Length of the object in millimeter
- Process: Unit conversion (mm to cm) = Length of the object in millimeter x 10
- Output: Length of the object in centimeter
LAB 4 - BIC10204
QUESTION 2:
2. Write a complete program following the algorithm given below.
2.1 Print a message to ask users to enter their names.
2.2 Read the name.
2.3 Print a message to ask users to enter their height and weight in kg and m.
2.4 Read weight and height.
2.5 Print name.
2.6 Print weight and height.
CODING & OUTPUT QUESTION 2:
QUESTION 3:
3. Write a complete program following the algorithm given below.
3.1 Declare identifier of integer data type named num1.
3.2 Declare identifier of float data type named num2.
3.3 Declare a constant called MAX with a value of 50.88.
3.4 Print a message to ask the user to enter a value for num1.
3.5 Read num1.
3.6 Print a message to ask the user to enter the value for num2.
3.7 Read num2.
3.8 Print num1, num2, and MAX.
CODING & OUTPUT QUESTION 3:
QUESTION 4:
4. Develop a simple subject registration system. The program requires the user to enter the student’s full name, I/C number, matric number, subject code, and subject name. Then the program will print out all the data that has been entered on the screen.
CODING & OUTPUT QUESTION 4:
Written by Arif😁.
LAB 5 - BIC10204
QUESTION a:
a. Convert this mathematical expression into C expression:
ANSWER FOR QUESTION a:
i) y = (m*x) + c
ii) ((2*a)/b)*(3*c)
iii) ((9*p)+(2*q*(r+2)))/(2*(s-1))
iv) (((3*e)-d)/(x-9))-(4-(3*pow(c,2))/(4*y))
QUESTION b:
b. Determine the order of solving the expressions below and calculate the value of x.
ANSWER FOR QUESTION b:
i) x = ((6/2)*3)+7-1
x = 3*3+6
x = 15
ii) x = (2%2)+(2*2)-(2/2)
x = 0+4-1
x = 3
iii) x = ((3/3)*9+3)*3*3
x = 12*9
x = 108
iv) x = (((4*3)/(12/2))+3)–(4*1)
x = (2+3)-4
x = 1
QUESTION c:
c. Given the value of num1=26. Determine the value of num2 after the execution for each of the following statement.
ANSWER FOR QUESTION c:
num1=26, num2
i) num2 = num1++ - 2;
num2 = 26 - 2;
num2 = 24;
ii) num2 = num1;
num2 = 27;
num2 = 27;
iii) num2 = ++num1 - 3;
num2 = 28 - 3;
num2 = 25;
iv) num2 = num1 + 1;
num2 = 28 + 1;
num2 = 29;
QUESTION d:
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).
ANSWER FOR QUESTION d:
i=3, j=4, k
i) k = j++;
k = 4;
ii) k = ++j;
k = 5;
iii) k = ++i * j--;
k = 16;
iv) k = j++ * --i;
k = 8;
v) k = j * i/j--;
k = 3;
vi) k = 24/j++ - 16 % i;
k = 5;
QUESTION e:
e. Determine the output of the program below.
ANSWER FOR QUESTION e:
1 = 10
2 = 10
3 = 11
4 = 12
5 = 12
6 = 31
7 = -11
8 = 33
9 = 33
10 = 33
11 = 0
12 = 1
13 = 0
QUESTION f:
f. Create expression for each of the following output. You may use unary or binary operators or combination of both. (Assume every statement is noncontiguous)
Given i = 2, j = 5.
Examples:
Output : 3 Answer : ++i;
Output : 6 Answer : i++ + --j;
i. 7
ii. 8
iii. 9
iv. 12
v. 36
ANSWER FOR QUESTION f:
i) printf("\n%d", i+j);
ii) printf("\n%d", (++i)+j);
iii) printf("\n%d", (++i)+(++j));
iv) printf("\n%d", i+(2*j));
v) printf("\n%d", (3*i)+(6*j));
Written by Arif😁.
LAB 6 - BIC10204
QUESTION a:
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.
CODING & OUTPUT a:
QUESTION b:
Table 1 shows classification of blood pressure based on the systolic blood pressure (SBP) and diastolic blood pressure (DBP) level and recommendations for follow up defined by The Seventh Report of the Joint National Committee on Prevention, Detection, Evaluation and Treatment of High Blood Pressure. Based on Table 1, write C program to determine blood pressure. This program will read SBP and DBP and display the blood pressure category and recommendation as an output messages.
QUESTION c:
Write a program using nested if statements that perform the following test:
If the variable employed is equal to ‘Y’ and if worklength is equal or greater than 5, then display the message “Your credit card application is accepted”. However, if worklength is less than 5, then display the message “Please provide a guarantor”. Otherwise, if the variable employed is equal to ‘N’, then display the message “Your credit card application is rejected”.
CODING & OUTPUT c:
QUESTION d:
Write a program to convert English unit to metric as unit by using switch … case statement. The conversion units as tabulated in Table 2.
CODING & OUTPUT d:
Written by Arif😁.
LAB 7 - BIC10204
QUESTION a:
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
CODING & OUTPUT a:
QUESTION b:
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
CODING & OUTPUT b:
QUESTION c:
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. Use the following formula to determine these amounts:
𝑎=𝑝(1+𝑟)^𝑛
Where;
𝑎 = the amount of deposit at the end of nth year
𝑝 = original amount saved
𝑟 = annual interest rate
𝑛 = number of year
CODING & OUTPUT c:
QUESTION d:
Write a C program to produce the following output by implementing nested loop using for statement.
Output:
Number 1 to 10:
Row 1:1 2 3 4 5 6 7 8 9 10
Row 2:1 2 3 4 5 6 7 8 9 10
Row 3:1 2 3 4 5 6 7 8 9 10
Row 4:1 2 3 4 5 6 7 8 9 10
Row 5:1 2 3 4 5 6 7 8 9 10
CODING & OUTPUT d:
Written by Arif😁.
LAB 8 - BIC10204
QUESTION 1(a) & (b):
1. Based on the function definition below, write a complete C program with the implementation of functions:
a. int GreaterThan(int no)
{
if (no > 10)
printf(“%d is greater than 10”, no);
else
printf(“%d is less than 10”, no);
}
b. int ExamGrade(char grade)
{
if (grade == ‘A’ || grade == ‘a’)
printf(“\nExcellent!”);
else if (grade == ‘B’ || grade == ‘b’)
printf(“\nGood”);
else
printf(“\nNot in the list”);
}
CODING & OUTPUT Q1(a):
CODING & OUTPUT Q1(b):
QUESTION 2:
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.
Please enter multiplication table: 3
3 Times Table
1 * 3 = 3
2 * 3 = 6
..
..
12 * 3 = 36
CODING & OUTPUT Q2:
QUESTION 3:
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.:
void BasicSalary() – Ask the user to enter basic salary.
void EPF(double) – To calculate the amount of employees evident fund (EPF) deduction from basic salary.
void CalculateBonus(double) – To calculate the amount of bonus. Assume bonus is half of the 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 the salary) is RM600.00
Your total pay is RM1200.00 – RM132.00 + RM600.00 = RM1668.00
CODING & OUTPUT Q3:
Written by Arif😁.
LAB 9 - BIC10204
QUESTION 1:
1. Write a program (C programming language) that reads 10 integer numbers into an array and display each of the values 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.
CODING & OUTPUT Q1:
QUESTION 2:
2. Write a program (C programming language) to store and print the names of your two favorite television programs. Store these programs in two-character arrays. Initialize one of the strings (assign it the first program’s name) at the time you declare the array. Initialize the second value in the body of the program with the strcpy() function.
CODING & OUTPUT Q2:
Written by Arif😁.
Comments
Post a Comment