Showing posts with label ALGORITHMCODINGS. Show all posts
Showing posts with label ALGORITHMCODINGS. Show all posts

Simplest way to learn C language: Best and simplest Algorithm to understand iterative & nested If condition

Now lets try and understand Algorithm of nested if condition and iterative if condition

Nested if else condition for finding the highest among the three numbers a, b and c.
  1. Start.
  2. Accept the value a, b, c.
  3. If a>b and a>c then
  4. Display a as greatest.
  5. Go to step 14.
  6. If a>b and a
  7. Display c as greatest.
  8. Go to step 14.
  9. If a<b and b>c then
  10. Display b as greatest.
  11. Go to step 14.
  12. If a
  13. Display c as greatest.
  14. End.
Now in the above algorithm even if the values of a and b or a and c or either of two values or all values of a,b and c are equal we can get the answer through it.
Through if condition we can work out the algorithm of Tables
  1. Start.
  2. Accept the value of a.
  3. Let b = 1.
  4. c = a × b.
  5. Express (display or print) c.
  6. Increment value of b by 1.
  7. If b <= 10 then go to step 4.
  8. If b >= 11 then go to step 9.
  9. End.
Focus on the above algorithm and remember that step 4, 5 and 6 are repeated till the value of b < 10 and as b goes beyond 10, step 8 executes and algorithm terminates. As you can observe carefully the recurrence of step 4, 5 and 6 is due to variance in the value of b. b is initialized in step 3, condition is checked for b in step 7 and value of b is incremented in step 6

Hack Facebook online psp,xbox games Hack Facebook Online

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