Monday, March 26, 2012

Program to find sum of first n natural,even and odd numbers,separately


/**************<soeasyprograms.blogspot.in>******************/
/*Program to find sum of first n natural,even & odd numbers,separately*/
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,i,even=0,odd=0;
   clrscr();
   printf("enter the value of n  ");
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   {
      if(i%2==0)
      even=even+i;
      else
      odd=odd+i;
      }
      printf("The sum of first %d natural even numbers is %d\n",n,even);
      printf("\nThe sum of first %d natural odd numbers is %d",n,odd);
      getch();
      }
  /*End of program*/
/**************<soeasyprograms.blogspot.in>******************/


No comments:

Post a Comment