• Follow Us

Sum of Even and Odd Numbers in a Given Range in C

Sum of Even and Odd Numbers in a Given Range in C

#include<stdio.h>
/* Learn C Programming at www.Codetaglance.com */
int main()
{
int i, Min, Max, SumEven = 0, SumOdd = 0;
printf("\n Please Enter the Min, and Max Limit Values : \n");
scanf("%d %d", &Min, &Max);
for(i = Min; i <= Max; i++)
{
   if ( i%2 == 0 ) 
   {
      SumEven = SumEven + i;
   }
   else
   {
      SumOdd = SumOdd + i;
   } 
}
printf("\n Sum of Even Numbers between %d and %d  = %d", Min, Max, SumEven);
printf("\n Sum of Odd Numbers between %d and %d  = %d", Min, Max, SumOdd);
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart