Thursday, February 17, 2011

program for display sum of all even number from 1 to n

#include<stdio.h>
#include<conio.h>
void main()
 {
 clrscr();
 int i,n,tot=0;
 printf("Enter any limit :-");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
  {
  if(i%2 == 0)
   {
   tot=tot+i;
   }
  }
 printf("Sum is %d",tot);
 getch();
 }

No comments: