Design an algorithm and the corresponding flowchart for finding the sum of the numbers 2, 4, 6, 8, ..., n
Answers
An algorithm and the flowchart for finding the sum of the numbers 2, 4, 6, 8, ..., n
Explanation:
Algorithm
Step 1. Start
Step 2. Declare numeric variables i, n and sum.
Step 3. Initialize sum = 0.
Step 4. Input upper limit says n to calculate the sum of even numbers.
Step 5. Iterate through even numbers using for loop from 2 to n and increment by 2 on each iteration. such as
for(i=2; i<=n; i+=2).
compute sum = sum + i.
repeat step 5
Step 6. Print sum
7. End
Flow chart is attached below
Following are the algorithm and flowchart is given below .
Explanation:
Algorithm
Step 1: Start
Step 2: declared a variable k and initialized 2 with them also declared a variable s1 and initialized s1 to 0 for the sum.
Step 3: Read the value of n1 by user.
Step 4: check loop condition while k< n1 if condition is true then goto step 5 otherwise go to step 6.
Step 5: s1=s1+k and k=k+2.
Step 6:Print s1.
Flowchart:
Following are the attachment of flowchart that is mention below
Learn More:
- brainly.in/question/14884805
- brainly.in/question/7294643