Simplest way to learn C language: Best and simplest Algorithm to understand If condition- Part 1

some remarkable examples for understanding algorithm of if condition

This time we will work out some example as we did a simple algorithm about addition of two numbers. In the previous example if we just change the “+” from -,* and / we can get algorithms about subtraction, multiplication and division respectively.
General feature of an algorithm is like: -
1. Start.
2. Variables name assumption or declaration.
3. Calculation block.
4. Expressing (display or print) answer.
5. End.
One more algorithm that we will learn is calculating simple interest: -
1. Start.
2. Principle amount, rate of interest, time.
3. Simple interest = (Principle amount × Rate of interest × Time)/100.
4. Display or Print Simple interest.
5. End.
Today’s lesson will be about algorithm of if condition: –
The simplest example of if condition will be:
Suppose we have to find a person is vegetarian or Non-vegetarian.
1. Start.
2. Accept a value for age.
3. If age => 18 then display “You are an adult”.
4. If age < 18 then display “You are not an adult”.
5. End.
Suppose we hire a two wheeler for number of hours and charges are as follows: -
For the first 5 hours: – Rs. 200/hr
For the next 5 hours: – Rs. 500/hr
For the next 5 hours: – Rs. 700/hr
Further any number of hours: – Rs. 1000/hr
Now suppose number of hours for which vehicle is hired is 7hrs, then the answer will not be (7×500) Rs.3500. Surprised, Guess why? Let us work out the algorithm for it and then you will realize what the fact is.
1. Start.
2. Accept the number of hours as A.
3. If A <= 5 then.
4. Answer = A × 200.
5. Express (display or print) Answer.
6. Go to step 18.
7. If A > 5 and A <= 10 then.
8. Answer = ((A – 5) × 500) + 1000.
9. Express (display or print) Answer.
10. Go to step 18.
11. If A > 10 and A <=15 then.
12. Answer = ((A – 10) × 700) + 3500.
13. Express (display or print) Answer.
14. Go to step 18.
15. If A > 15 then.
16. Answer = ((A – 15) × 1000) + 7000.
17. Express (display or print) Answer.
18. End.
Focus on the statements that are highlighted in bold and you will realize that.
If the number of hour exceeds the previous slab then reduce that many hours (i.e. – (A-5),(A-10) and (A-15)) from the actual number of hours and find the value for the current slab by multiplying it by current slab charge, and later add the maximum chargeable amount (i.e. – 1000,3500 and 7000) of the previous slab to it.

Hack Facebook online psp,xbox games Hack Facebook Online

No comments:

Post a Comment