Sum of 1 to n even numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,sum=0,n;
clrscr();
printf("enter the number \n");
scanf("%d",&n);
while(i<=n)
{
if(i%2==0)
{
sum=sum+i;
}
i++;
}
printf("sum of even number=%d",sum);
getch();
}

Comments

  1. well i need an one condition here to add also the negative numbers with the even numbers

    ReplyDelete
  2. please how to solve write a c program to find sum all even & odd number between 1 to n ? please solve to me ....

    ReplyDelete

Post a Comment