C Program to Find Sum of all Even Numbers b/w 1 to n Using For Loop
Q:- Write a C Program to Find Sum of all Even Numbers b/w 1 to n Using
For Loop ?
Input
#include<stdio.h>
#include<conio.h>
main()
{
int num,i,s=0;
clrscr();
printf(“Enter a Limit of N=”);
scanf(“%d”,&num);
for(i=2;i<=num;i++)
{
s=s+i;
}
printf(“Sum of all Even Numbers =
%d”,s);
getch();
}
Output
Enter a
Limit of N = 5
Sum of all
Even Numbers = 6
Comments
Post a Comment