Print the sum of all even numbers between 1 to n. n should be given by the user.
Answers
Answered by
2
Answered by
0
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 .
Similar questions