Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Programming Exercise 2 1. State whether identifier. a. b. c. d. e. f. the given identifiers are VALID or INVALID.

Give reason for the invalid R3D3 mark1 mark 2 per-capita 10sen integer g. h. i. j. k. l. num1*num2 WangBesar phone# xxx double upin&ipin

2. Rewrite this mathematical equation using C statement: x = b2 - 4ac a-c 3. Write an abbreviated statement using compound operator for this statement: x = y + x + 10; 4. Which of the following is a valid defined constant? a. #define SALES-TAX-RATE = 0.0825 b. #define SALES-TAX-RATE 0.0825 c. #define SALES_TAX_RATE 0.0825 d. #define SALES_TAX_RATE 0.0825; 5. What are the outputs for these printf( ) statements? a. printf( %d , 8/4); b. printf( The result is: %d , 15%2); c. printf( 10\t20\n30\n ); d. int a=5; float price=1.2; printf( Total is: %.2f\n , a*price); 6. Write the output for the following program. For clarity, use the symbol star ( * ) to denote a blank space. a) b) double a= 1.23, b= 1.23; int x=5, y=3, z; printf( %8s\n , Good ); printf("%5d\n", x); printf( %-6s\n , LUCK ); printf("%-5d\n", x); printf( %5.3f %-7.2f\n", a, b); printf("%7s\n","Ali"); printf("%-7s\n", "Ali"); printf("%d" , x/y); x = x * 10 ; y *= y ; z = 10 * y % x; printf("%d\n", z);

7. If num is a variable of type int and temp is a variable of type double, how could you complete this scanf statement? scanf("_________________", _____________________); 8. Given a is 3, b is 4, and c is 5, what is the value of answer? answer = --a * (3 + b) / 2 - c++ * b 9. If a human heart beats on the average of once a second, how many times does the heart beat in a lifetime of n years? (Use 365 for days in a year). Write a program to count the number of heart beat. 10. Write a C program which: a) Declares 5 variables: quiz1, quiz2, quiz3, totalmark, average b) Prompts the user to enter marks for quiz1, quiz2 and quiz3 c) Calculates the total mark d) Calculates the average mark e) Displays the total mark and the average mark 11. Write a program to print the payroll report. The user should input name, working hours per week, and a pay rate. The payroll tax rate is fixed at 7.2%. The program should print the report as follows: *********************************************** WELCOME TO PAYROLL SYSTEM *********************************************** Name : Ahmad Hours worked per week : 40 Pay rate (RM) : 2.00 **************** Salary Report for Ahmad ****************** Hours worked : 40 Gross Salary (RM) : 80 Tax : 0.072 Deduction (RM) : 5.76 Net Salary (RM) : 74.24 12. Write a program that can convert seconds to hours, minutes and seconds. Sample input and the results are shown below. Enter total number of seconds to be converted: 7655 7655 seconds = 2 hours, 7 minutes and 35 seconds

You might also like