Print sum of even and odd numbers from 1 to N numbers.

 WAP to print sum of even and odd numbers from 1 to N numbers.


#include<stdio.h>

#include<conio.h>

void main()

{

  int num,i,sumEven=0,sumOdd=0;

  clrscr();

  printf("\n Enter the limit :");

  scanf("%d",&num);

  for(i=1;i<=num;i++)

  {

    if(i%2==0)

     sumEven=sumEven+i;

    else

     sumOdd=sumOdd+i;

  }

  printf("\n Sum of Even numbers :%d",sumEven);

  printf("\n Sum of Odd numbers  :%d",sumOdd);

  getch();

}


Output:-

Enter the limit

10

Sum of Even numbers : 30

Sum of Odd numbers :  25


Post a Comment

0 Comments