Programs on If Statement

Basic WAP (Write A Program) Questions

  1. Check if a number is even or odd
Input:
Enter a number: 5
Output:
Number 5 is odd
  1. Check if the last digits of two numbers are the same
Input:
Enter number 1: 55
Enter number 2: 45
Output:
Last digits of 55 and 45 are same
  1. Check if a triangle can be formed from 3 angles
Input:
Enter value for angle a: 50
Enter value for angle b: 60
Enter value for angle c: 70
Output:
Triangle can be formed
  1. Check if a triangle is equilateral
Input:
Enter value for angle a: 60
Enter value for angle b: 60
Enter value for angle c: 60
Output:
Triangle is equilateral triangle
  1. Check if student is passed based on marks of 5 subjects
Input:
Enter marks for maths: 50
Enter marks for science: 50
Enter marks for history: 50
Enter marks for english: 50
Enter marks for marathi: 50
Output:
Total Marks: 250
Percentage: 50%
Student is passed
  1. Find the greatest of two numbers
Input:
Enter number 1: 50
Enter number 2: 60
Output:
60 is greater than 50
  1. Find the greatest of three numbers
Input:
Enter number 1: 50
Enter number 2: 60
Enter number 3: 70
Output:
70 is greater than 50 and 60
  1. Check if the sum of cube of digits equals the number (Armstrong number)
Input:
Enter a 3 digit number: 153
Output:
Success: Sum of cube of 153 is 153
  1. Check if last digits of three numbers are the same
Input:
Enter number 1: 50
Enter number 2: 60
Enter number 3: 70
Output:
Last digits of 50, 60 and 70 are same
  1. Check if a number is a palindrome
Input:
Enter a number: 121
Output:
121 is palindrome number
  1. Print total, percentage and result (pass/fail) from 5 subject marks
Input:
Enter marks for maths: 50
Enter marks for science: 50
Enter marks for history: 50
Enter marks for english: 50
Enter marks for marathi: 50
Output:
Total Marks: 250
Percentage: 50%
Student is passed
  1. Check type of triangle based on angles
Input:
Enter value for angle a: 45
Enter value for angle b: 45
Enter value for angle c: 90
Output:
Triangle can be formed
The triangle is right angled triangle
  1. Check marriage eligibility based on age and gender
Input:
Enter gender M or F: M
Enter your age: 30
Output:
30 ka ho gaya ab to shadi kar le
  1. Check if a year is a leap year
Input:
Enter year: 2004
Output:
Year 2004 is a leap year
  1. Calculate commission based on salary
Salary		Commission
<10000		10%
10000-20000	12%
>20000		15%

Input:
Enter Salary: 10000
Output:
Your commission is 1000 Rupees
  1. Print division based on percentage
Percentage	Division
>=75		1st class with distinction
60-75		1st class
50-60		2nd class
40-50		3rd class
<40		Fail

Input:
Enter marks for maths: 75
Enter marks for science: 75
Enter marks for history: 75
Enter marks for english: 75
Enter marks for marathi: 75
Output:
Total Marks: 375
Percentage: 75%
Student passed with 1st class Distinction

Leave a Reply

Your email address will not be published. Required fields are marked *