Write algorithms and flow charts for the following
1. Find the sum of first five natural numbers.
2. Interchange the value of two variables.
3. Find area of circle.
4. Find the number is even or odd.
Answers
Answer:
Algorithms:
A) Find the sum of first five natural numbers.
In this algorithm, i and sum are two integer variables.
1. START
2. i ⟵ 1
3. sum ⟵ 0
4. while ( i <= 5 ) do
5. sum ⟵ sum + i
6. i ⟵ i + 1
7. end while
8. display sum
9. END
B) Interchange the value of two variables.
In this algorithm, a and b are two integer variables value entered by user. temp is an another integer variable used to keep temporary data in it.
1. START
2. get numbers a and b
3. temp ⟵ a
4. a ⟵ b
5. b ⟵ temp
6. Display a and b
7. END
C) Area of circle.
In this algorithm, r is the integer variable which holds the value of Radius and area is another floating point variable to calculate area of the circle. ( π = 3.14159)
1. START
2. get radius of circle, r
3. area ⟵ 3.14159 * r * r
4. Display area
5.END
D)Find the number is even or odd.
In this algorithm, num is an integer variable value entered by user.
1. START
2.get number num
3. if ( num % 2 == 0 ) then
4. display "number is EVEN"
5. else
6. display "number is ODD"
7. end if
8. END
Note: I hope that it will help you and Now you can Draw flowchart of your own with the help of these algorithm.
** Please mark this ans as Brainliest answer. Thank you!
Answer:
sup
Explanation:
A) Find the sum of first five natural numbers.
In this algorithm, i and sum are two integer variables.
1. START
2. i ⟵ 1
3. sum ⟵ 0
4. while ( i <= 5 ) do
5. sum ⟵ sum + i
6. i ⟵ i + 1
7. end while
8. display sum
9. END
B) Interchange the value of two variables.
In this algorithm, a and b are two integer variables value entered by user. temp is an another integer variable used to keep temporary data in it.
1. START
2. get numbers a and b
3. temp ⟵ a
4. a ⟵ b
5. b ⟵ temp
6. Display a and b
7. END
C) Area of circle.
In this algorithm, r is the integer variable which holds the value of Radius and area is another floating point variable to calculate area of the circle. ( π = 3.14159)
1. START
2. get radius of circle, r
3. area ⟵ 3.14159 * r * r
4. Display area
5.END
D)Find the number is even or odd.
In this algorithm, num is an integer variable value entered by user.
1. START
2.get number num
3. if ( num % 2 == 0 ) then
4. display "number is EVEN"
5. else
6. display "number is ODD"
7. end if
8. END