Write a C-program to print sum of even numbers using for loop?
Write a C-program to print sum of even numbers using for loop?
Write a C-program to print sum of even numbers using for loop
#include <stdio.h>
int main() {
int x,n,sum=0;
printf("Enter n value ");
scanf("%d",&n);
for(x=1;x<=n;x++)
{
if(x%2==0)
{
sum=sum+x;
}
}
printf("%d sum is %d",n ,sum);
return 0;
}