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

If Statement Problem

Gg

Uploaded by

terabox8872
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

If Statement Problem

Gg

Uploaded by

terabox8872
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Finding the Largest of Three Numbers

Algorithm:

1. Take three numbers as input.


2. Compare the first number with the second and third numbers.
3. If the first number is the largest, print it as the largest.
4. If not, compare the second number with the third.
5. If the second number is the largest, print it as the largest.
6. Otherwise, print the third number as the largest.

2. Check if a Year is a Leap Year

Algorithm:

1. Take a year as input.


2. Check if the year is divisible by 4.
o If not, it's not a leap year.
o If yes, check if it is divisible by 100.
▪ If not, it is a leap year.
▪ If yes, check if it is divisible by 400.
▪ If yes, it is a leap year.
▪ If not, it is not a leap year.

3. Grade Calculator Based on Marks

Algorithm:

1. Take the student's marks as input.


2. Compare the marks with different grade thresholds.
o If marks are 90 or above, assign grade 'A+'.
o If marks are 80 or above, but less than 90, assign grade 'A'.
o If marks are 70 or above, but less than 80, assign grade 'B+'.
o If marks are 60 or above, but less than 70, assign grade 'B'.
o If marks are 50 or above, but less than 60, assign grade 'C'.
o If marks are below 50, assign grade 'F'.
3. Print the assigned grade.

4. Complex Nested Conditions for User Authentication

Algorithm:

1. Take input for username, password, and two-factor authentication code.


2. Check if the input username matches the stored username.
o If not, print an invalid username message.
3. If the username is correct, check if the input password matches the stored password.
o If not, print an invalid password message.
4. If both username and password are correct, check if the two-factor authentication code
matches.
o If yes, grant access.
o If no, deny access.
5. Categorizing a Number

Algorithm:

1. Take a number as input.


2. Check if the number is less than 0.
o If yes, categorize it as negative.
3. If not, check if the number is less than 50.
o If yes, categorize it as small.
4. If not, check if the number is less than 100.
o If yes, categorize it as medium.
5. If not, check if the number is less than 200.
o If yes, categorize it as large.
6. If none of the above, categorize it as very large.

6. ATM Withdrawal System Simulation

Algorithm:

1. Take input for withdrawal amount and PIN.


2. Check if the entered PIN matches the stored PIN.
o If not, print incorrect PIN message.
3. If PIN is correct, check if the withdrawal amount is less than or equal to the account balance.
o If not, print insufficient balance message.
4. If balance is sufficient, check if the withdrawal amount is a multiple of 100.
o If not, print message that amount must be in multiples of 100.
5. If all conditions are met, deduct the amount from the balance and print the new balance.

7. Quadratic Equation Solver

Algorithm:

1. Take coefficients a, b, and c as input.


2. Check if a is zero.
o If yes, print that it's not a quadratic equation.
3. If a is not zero, calculate the discriminant using the formula b2-4ac
4. Check the value of the discriminant:
o If greater than 0, compute and print two distinct real roots.
o If equal to 0, compute and print one real root.
o If less than 0, compute and print two complex roots.

8. E-commerce Discount Calculation

Algorithm:

1. Take user type and purchase amount as input.


2. Check the user type and purchase amount:
o For "regular" user:
▪ Less than 100: 5% discount
▪ 100 to 500: 10% discount
▪ Above 500: 15% discount
o For "premium" user:
▪ Less than 100: 10% discount
▪ 100 to 500: 15% discount
▪ Above 500: 20% discount
o For "vip" user:
▪ Less than 100: 15% discount
▪ 100 to 500: 20% discount
▪ Above 500: 25% discount
3. If user type is invalid, set discount to 0 and print an error message.
4. Calculate discount amount and final price.
5. Print discount and final price.

9. BMI Calculator with Category

Algorithm:

1. Take weight and height as input.


2. Calculate BMI using the formula weight/(height2)
3. Compare the BMI value with categories:
o Less than 18.5: Underweight
o 18.5 to 24.9: Normal weight
o 25 to 29.9: Overweight
o 30 and above: Obesity
4. Print the BMI value and corresponding category.

10. Email Validation System

Algorithm:

1. Take an email as input.


2. Check if email contains both "@" and "." symbols.
3. Find the index of "@" and last index of ".".
4. Check the following conditions:
o "@" appears before the last "."
o "." is not the last character.
o "@" is not the first character.
5. If all conditions are met, print "Email is valid."
6. Otherwise, print "Invalid email."

11. Eligibility Check for Loan Application

Algorithm:

1. Take age, annual income, and credit score as input.


2. Check if the age is 18 or above:
o If not, print not eligible.
3. If age is valid, check if annual income is 30,000 or more:
o If not, print not eligible.
4. If income is valid, check if credit score is 700 or more:
o If yes, print eligible.
o If not, print not eligible due to low credit score.
12. Advanced Ticket Pricing System

Algorithm:

1. Take age and show type as input.


2. Check age category:
o Less than 12: Child pricing
o 12 to 59: Adult pricing
o 60 and above: Senior pricing
3. For each age category, set different prices based on show type (regular, 3D, or IMAX).
4. Print the calculated ticket price.

13. Password Strength Checker

Algorithm:

1. Take password as input.


2. Check if password length is at least 8 characters.
o If not, print password too short.
3. Check for at least one uppercase letter, one lowercase letter, one digit, and one special
character.
4. If all conditions are met, print strong password.
5. If three conditions are met, print medium strength.
6. If less than three conditions are met, print weak password.

14. Complex Shopping Cart Calculation

‘Algorithm:

1. Create a list of items in the cart with price and quantity.


2. Calculate subtotal by multiplying price and quantity for each item.
3. Check if subtotal is above 500:
o If yes, apply 10% discount.
4. Calculate discount amount.
5. Calculate 7% tax on discounted subtotal.
6. Calculate final total by adding tax to discounted subtotal.
7. Print subtotal, discount, tax, and final total.

You might also like