Q Basic program sum of first n even numbers
please someone say
Answers
Answered by
2
Answer:
To find sum of even numbers we need to iterate through even numbers from 1 to n. Initialize a loop from 2 to N and increment 2 on each iteration. The loop structure should look like for(i=2; i<=N; i+=2) . Inside the loop body add previous value of sum with i i.e. sum = sum + i .
Explanation:
hope it helps
Answered by
4
To find sum of even numbers we need to iterate through even numbers from 1 to n. Initialize a loop from 2 to N and increment 2 on each iteration. The loop structure should look like for(i=2; i<=N; i+=2) . Inside the loop body add previous value of sum with i i.e. sum = sum + i .
Example :
Input : n = 4
Output : 20
Sum of first 4 even numbers
= (2 + 4 + 6 + 8) = 20
Input : n = 20
Output : 420
Similar questions