//A C program to find sum of even numbers between 1 to N using for loop
#include<stdio.h>#include<conio.h>
void main()
{
clrscr();
int i, n, sum=0;
printf("Enter tne number: ");
scanf("%d", &n);
for(i=2; i<=n; i+=2)
{
sum += i;
}
printf("Sum of all even number between 1 to %d = %d", n, sum);
getch();
}
Output:
Nhận xét
Đăng nhận xét