Professional Documents
Culture Documents
If Else Exercises
If Else Exercises
(Positive, Negative) Write a program that reads an integer from the user. Then your program should display a message
indicating whether the integer is negative, positive or zero. If it is not zero, it should also tell whether the inputted number
is odd or even.
Name: _______________________________________Section:__________________Date:_____________
(Divisible) Write a C program to check whether a number id ODD or EVEN. If it ODD, it should also check whether it is
divisible by 5 and 11 or not.
Name: _______________________________________Section:__________________Date:_____________
(Vowel or Consonant) In this exercise you will create a program that reads a letter of the alphabet from the user. If the
user enters a, e, i, o or u then your program should display a message indicating that the entered letter is a vowel. If the
user enters y then your program should display a message indicating that sometimes y is a vowel, and sometimes y is a
consonant. Otherwise your program should display a message indicating that the letter is a consonant.
Name: _______________________________________Section:__________________Date:_____________
(Day of the week) Write a C program to input week number and print week day.
Name: _______________________________________Section:__________________Date:_____________
(Days of the month) Write a C program to input month number and print number of days in that month.
Bonus Problem: (20 points)
(Separating Digits in an Integer) Write a program that inputs one five-digit number, separates the number into its
individual digits and prints the digits separated from one another by three spaces each. [Hint: Use combinations of integer
division and the remainder operation.] For example, if the user types in 42139, the program should print
Name: _______________________________________Section:__________________Date:_____________
(Valid Triangle) Write a C program to input angles of a triangle and check whether triangle is valid or not.
Name: _______________________________________Section:__________________Date:_____________
(Name that Triangle) A triangle can be classified based on the lengths of its sides as equilateral, isosceles or scalene. All
3 sides of an equilateral triangle have the same length. An isosceles triangle has two sides that are the same length, and a
third side that is a different length. If all of the sides have different lengths then the triangle is scalene. Write a program
that reads the lengths of 3 sides of a triangle from the user. Display a message indicating the type of the triangle.
Name: _______________________________________Section:__________________Date:_____________
(Grade points to Letter Grade) Write a C program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate average and grade according to following:
< 50% F
Grade Points Letter Grade
>= 90% A
Note: Floating point values should be accepted.
>= 80% B
Bonus Problem: (20 points)
>= 70% C (Separating Digits in an Integer) Write a program that
inputs one five-digit number, separates the number into its
>= 60% D individual digits and prints the digits separated from one
another by three spaces each. [Hint: Use combinations of
>= 50% E integer division and the remainder operation.] For example,
if
Name: _______________________________________Section:__________________Date:_____________
(Comparing Integers) Write a program that asks the user to enter two integers, obtains the numbers from the user, and
then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These
numbers are equal.”
Name: _______________________________________Section:__________________Date:_____________
(Diameter, Circumference and Area of a Circle) 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 calculations inside
the printf statement(s) and use the conversion specifier %f.
Name: _______________________________________Section:__________________Date:_____________
(Multiples) Write a program that reads in two integers and determines and prints if the first is a multiple of the second.
[Hint: Use the remainder operator.]
Name: _______________________________________Section:__________________Date:_____________
(Sound Levels) Write a program that reads a sound level in decibels from the user. If the user enters a decibel level that
matches one of the noises in the table then your program should display a message containing only that noise. If the user
enters a number of decibels between the noises listed then your program should display a message indicating which noises
the level is between. Ensure that your program also generates
reasonable output for a value smaller than the quietest noise in the
table, and for a value larger than the loudest noise in the table.
Name: _______________________________________Section:__________________Date:_____________
Write a program that reads a wavelength from the user and reports its
color. Display an appropriate error message if the wavelength entered by
the user is outside of the visible spectrum.
Name: _______________________________________Section:__________________Date:_____________
(Is it a Leap Year?) Most years have 365 days. However, the time required for the Earth to orbit the Sun is actually
slightly more than that. As a result, an extra day, February 29, is included in some years to correct for this difference.
Such years are referred to as leap years. The rules for determining whether or not a year is a leap year follow:
Leap Year:
If a year is divisible by 4, 100 and 400 then it is a leap year.
If a year is divisible by 4 but not divisible by 100 then it is a leap year
Write a program that reads a year from the user and displays a message indicating whether or not it is a leap year.
Name: _______________________________________Section:__________________Date:_____________
Scoring:
1.
1. Write a C program to find maximum between two numbers.
2. Write a C program to find maximum between three numbers.
3. Write a C program to check whether a number is even or odd.
4. Write a C program to check whether a character is uppercase or lowercase alphabet.
5. Write a C program to count total number of notes in given amount.
6. Write a C program to input all sides of a triangle and check whether triangle is valid or not.
7. Write a C program to find all roots of a quadratic equation.
8. Write a C program to calculate profit or loss.
9. Write a C program to check whether a character is alphabet or not.
10. Write a C program to input any character and check whether it is alphabet, digit or special character.