0% found this document useful (0 votes)
15 views

Assignment on If else

The document outlines a series of programming exercises involving conditional structures. Each exercise includes a prompt for user input and a corresponding solution demonstrating the expected output. Topics covered include determining even/odd numbers, finding the largest of integers, checking leap years, calculating telephone bills, solving quadratic equations, calculating average grades, mapping numbers to days of the week, and identifying vowels or consonants.

Uploaded by

Vivek Pathade
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Assignment on If else

The document outlines a series of programming exercises involving conditional structures. Each exercise includes a prompt for user input and a corresponding solution demonstrating the expected output. Topics covered include determining even/odd numbers, finding the largest of integers, checking leap years, calculating telephone bills, solving quadratic equations, calculating average grades, mapping numbers to days of the week, and identifying vowels or consonants.

Uploaded by

Vivek Pathade
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Conditional Structures

1. Write a program that prompts the user to input a number and display if the number is even or
odd.

Solution : Enter the Number:1

Given number is odd

2. Write a program that prompts the user to input two integers and outputs the largest.

Solution : a=14

b=46

3. Write a program that prompts the user to input three integers and outputs the largest.

Solution : Enter first number4

Enter second number56

Enter third number54

56

4. Write a program that prompts the user to input a year and determine whether the year is a leap
year or not. Leap Years are any year that can be evenly divided by 4. A year that is evenly divisible by
100 is a leap year only if it is also evenly divisible by 400. Example : 1992 Leap Year 2000 Leap Year
1900 NOT a Leap Year 1995 NOT a Leap Year

Solution : Enter the year2001

given year is not leap

5. Write a program that prompts the user to input number of calls and calculate the monthly
telephone bills as per the following rule: Minimum Rs. 200 for up to 100 calls. Plus Rs. 0.60 per call
for next 50 calls. Plus Rs. 0.50 per call for next 50 calls. Plus Rs. 0.40 per call for any call beyond 200
calls.

Solution : Enter the total number of calls70

Your bill amount = 200

6. The roots of the quadratic equation ax2 + bx + c = 0, a ≠ 0 are given by the following formula: In
this formula, the term b2 - 4ac is called the discriminant. If b2 - 4ac = 0, then the equation has two
equal roots. If b2 - 4ac > 0, the equation has two real roots. If b2 - 4ac < 0, the equation has two
complex roots. Write a program that prompts the user to input the value of a (the coefficient of x2 ),
b (the coefficient of x), and c (the constant term) and outputs the roots of the quadratic equation.
Solution : Enter the coefficient of x22

Enter the coefficient of x3

Enter the coefficient term5

discri = -31
The equation has two complex rootes

7. The marks obtained by a student in 3 different subjects are input by the user. Your program
should calculate the average of subjects and display the grade. The student gets a grade as per the
following rules: Average Grade 90-100 A 80-89 B 70-79 C 60-69 D 0-59 F

Solution : Enter the marks of c programing4

Enter the marks of python programing62

Enter the marks of java programing70

Total marks = 177

Average marks = 59.0

8. Write a program that prompts the user to input a number. Program should display the
corresponding days to the number. For example if user type 1 the output should be Sunday. If user
type 7 the output should be Saturday.

Solution : Enter a number from 1 to 7

4 is Wensday

9. Write a program that prompts the user to input a character and determine the character is vowel
or consonant.

Solution : Enter a letter

r is a constant

You might also like