Question:c program to sum odd and even numbers within a range 

Answer 
#include<stdio.h>

int main(){

    int number;
    int min,max;
    long odd_sum =0,even_sum = 0;
  
    printf("Enter the minimum range: ");
    scanf("%d",&min);

    printf("Enter the maximum range: ");
    scanf("%d",&max);

    for(number = min;number <= max; number++)
         if(number % 2 != 0)
             odd_sum = odd_sum + number;
         else
             even_sum = even_sum + number;

    printf("Sum of even numbers in given range is: %ld\n",even_sum);
    printf("Sum of odd numbers in given range is: %ld",odd_sum);
  
    return 0;

}
Sample output: Enter the minimum range: 1 Enter the maximum range: 10 Sum of even numbers in given range is: 30 Sum of odd numbers in given range is: 25 

+ ExplanationNot Moderated
+ Report
Total Preview: 885
c program to sum odd and even numbers within a range
Copyright © 2024. Powered by Intellect Software Ltd