$25
Question 1
What is the output of the following statements?
i. printf( “%.2f\n”, 3.446);
ii. printf(“%.1f\n”, 3.446);
Question 2
Write statements to,
i. Print the value 123.4567 with 2 digits precision.
ii. Print the value 3.14159 with three digits to the right of the decimal point.
iii. Print the value 333.546372 in a field width of 15 characters with precisions of 1,2,3,4 and 5.
Question 3
Draw a flow chart to enter the radius of a circle from the keyboard and display the diameter, the circumference and the area.
Convert the above flow chart into a C program.
Question 4
Draw a flow chart to enter the time duration of an event in seconds and display the hrs, minutes and seconds of the duration separately.
Additional Exercises
Question 1
a) What does the following print? Assume x = 2 and y = 3.
i. printf( “*\n**\n***\n****\n*****\n” ); ii. printf( “%d”, x + x ); iii. printf( “x = “); iv. printf( “x=%d”, x);
v. printf( “%d = %d”, x+y, y+x); vi. /* printf( “%d”, x+y ); */ vii. printf(“\n”);
viii. float z = 45.567; printf(“value is %.2f”, z);
Question 2
To travel from home to SLIIT Campus, a particular student needs to take three buses. Draw a flow chart to input the fares of each bus and estimate the traveling expenditure of the student for the entire semester.
Convert the above flow chart into a C program.
(Assume that there are 5 days per week and 13 weeks for the semester).
Question 3
The simple interest on a loan is calculated by the formula
interest = principal * rate * days / 365
The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal ,rate and days for several loans, and will calculate and display the simple interest for each loan
Question 4
The Body Mass Index (BMI) is given by
Create a BMI calculator application that reads the user’s weight then calculates and displays the user’s body mass index.
Question 5
Write a C program to find the sum of series 1+2+3+4+..+n using the following formula. The program should take the value of n from the key board.
Sum = n * (n+1) * (1/2)
Question 6
Write a program that inputs one five-digit number, separates the number into its individual digits and prints the digits separated from one another.
Ex: if user types, 42139, the program should print 4 2 1 3 9