Computer Science, asked by amartyasrimani38041, 1 year ago

Write a program to find the sum of all even numbers from 1 to n where the value of n is taken as input. [for example when n is 10 then the sum is 2+4+6+8+10 = 30]

Answers

Answered by zoekar26
0

Answer:

I wrote it in C. Hope it helps

Explanation:

#include <stdio.h>

#include <stdlib.h>

main(){

int sum, i, n;

printf("Give a number: ");

scanf("%d", &n);

sum = 0;

for(i=0;i<n;i++){

if(i%2==0){

sum = sum + i;

}

}

printf("The sum is %d", sum);

system("pause");

}

Similar questions