Mid Sem 190209
Mid Sem 190209
Find the error in each of the following code segment and explain how to correct it.
(note: there may be more than one error per statement):
1
Part B:Answer any 3 of the 6 questions.
1. Write a program that ask the user to enter two numbers, obtains the two
numbers from the user and prints the sum, product, and different of the two
numbers.
4. What is wrong with the following while repetition statement (assume z has
value 1000), which is supposed to calculate the sum of the integers from 100
down to 1;
while ( z >=0)
sum +=z;
2
Part C: Answer any 2 of the 4 questions.
1. Write a program that reads in the radius of a circle and prints the circle's
diameter, circumference and area. Use the constant value 3.14159 for Π.
Perform each of these calculation inside the printf statements and use the
conversation specifier %f.
the preceding formula assumes that rate is the annual ineterest 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, using the preceding formula. Here is a
sample input/output dialog.
#include <stdio.h>
int main()
{
int counter;
int grade;
int total;
int average;
total = 0;
counter = 1;
4. By using for repetition statement. Write a program that calculates and prints
the sum of the even integers from 2 to 30.