You are on page 1of 3

Assignment

Last date of submission: Wednesday 13-04-2011 Solve these questions with if else statement as well as Switch Statement Q1. Write appropriate if statements for each of the following conditions: a. If angle is equal to 90 degrees print the message The angle is a right angle, else print the message The angle is not a right angle. b. If the temperature is above 100degrees display the message above the boiling point of water, else display the message below the boiling point of water. c. If the number is positive add the number to possum, else add the number to negsum. d. If the voltage is less than .5 volts set the variable flag to zero, else set flag to one. e. If the difference between voltsl and volts2 is less than .001,set the variable approx to zero, else calculate approx as the quantity (voltsl - volts2) / 2.0. f. If the frequency is above 60hertz, display the message Frequency is too high. g. If the difference between templ and temp2 exceeds 2.3 degrees, calculate error as (templ - temp2) * factor. h. If x is greater than y and z is less than 20, read in a value for p. i. If distance is greater than 20and less than 35, read in a value for time. Q2. Write a C program that prompts the user to type in a voltage. If the entered voltage is greater than 12,the program should print the message Battery is charging, otherwise the program should print the message Battery is discharging. Q3. Write a C program that asks the user to input two numbers. If the first number entered is greater than the second number the program should print the message, The first number is greater, else it should print the message The first number is smaller. Test your program by entering the numbers 5 and 8 and then using the numbers 11 and 2. What do you think your program will display if the two numbers entered are equal? Q4. Modify Program 4-5 to accept both lower and uppercase letters as marriage codes. For example, if a user enters either an m or an M, the program should display the message Individual is married.

Q5. An angle is considered acute if it is less than 90 degrees, obtuse if it is greater than 90 degrees, and a right angle if it is equal to 90 degrees. Using this information write a C program that accepts an angle in degrees and displays the type of angle corresponding to the degrees entered. Q6. If money is left in a particular bank for more than two years, the interest rate given by the bank is 8.5 percent, else the interest rate is 7 percent. Write a C program that uses the scanf ( ) function to accept the number of years into the variable nyrs and display the appropriate interest rate depending on the input value. Q6. In a pass/fail course, a student passes if the grade is greater than or equal to 70 and fails if the grade is lower. Write a C program that accepts a grade and prints the message A passing grade or A failing grade, as appropriate. Q7. Write a C program to compute and display a person's weekly salary as determined by the following conditions: If the hours worked are less than or equal to 40, the person receives $8.00 per hour; else the person receives $320.00 plus $12.00 for each hour worked over 40 hours. The program should request the hours worked as input and should display the salary as output. Q8. A senior engineer is paid $1000 a week and a junior engineer $600 a week. Write a C program that accepts as input an engineer's status in the character variable status. If status equals's', the senior person's salary should be displayed, else the junior person's salary should be output. Q10. Write a C program that accepts a character as input data and determines if the character is an uppercase letter. An uppercase letter is any character that is greater than or equal to 'A' and less than or equal to 'Z'. If the entered character is an uppercase letter, display the message The character just entered is an uppercase letter. If the entered letter is not uppercase, display the message The character just entered is lowercase. Q11. Write a program that displays either the message I FEEL GREAT TODAY! or I FEEL DOWNTODAY#$*!, depending on the input. If the character u is entered in the variable code, the first message should be displayed; else the second message should be displayed. Q12. The interest rate used on funds deposited in a bank is determined by the amount of time the money is left on deposit. For a particular bank, the following schedule is used: Time on Deposit greater than or equal to 5 years less than 5 years but greater than or equal to 4 years Interest Rate 095 090

less than 4 years but greater than or equal to 3 years 085 less than 3 years but greater than or equal to 2 years 075 less than 2 years but greater than or equal to 1 year 065 less than 1 year 058 058 Using this information, write a C program that accepts the time that program that accepts the time that funds are left on deposit and displays the interest rate corresponding to the time entered. Q13. Rewrite the following if-else chain using a switch statement:
if (let_grad == 'A') printf("The numerical grade is between 90 and 100"); else if (let_grad == 'B') printf("The numerical grade is between 80 and 89.9"); else if (let_grad == 'C') printf("The numerical grade is between 70 and 79.9"); else if (let_grad == 'D'); printf("How are you going to explain this one"); else printf("Of course I had nothing to do with my grade."); printf("\nThe professor was really off the wall.");

Q14. Rewrite the following if-else chain using a switch statement:


if (res_typ
{

== 1)

in_data ( ); check ( );
}

else if (res_typ 2)
{

capacity ( ) devtype( ) else if (res_typ 3) volume ( ); mass ( ); else if (res_typ 4) area ( ); weight ( );
}

else if (res_typ 5)
{

files.( ); save ( );
}

else if (res_type 6) retrieve ( }; screen ( );

Q15. Each disk drive in a shipment of these devices is stamped with a code from 1 through 4, which indicates a drive of the following type:
Disk Drive Type 360kilobyte drive (5 1/2 inch) 2 1.2megabyte drive (5 1/2 inch) 3 722kilobyte drive (3 1/4 inch) 4 1.4megabyte drive (3 1/4 inch) Write a C program that accepts the code number as an input and, based on the value entered, displays the correct disk drive type.
Code 1

You might also like