Question:Sum of odd numbers in c within a range. 

Answer 
#include<stdio.h>

int main(){

    int number;
    int min,max;
    long 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)
             sum = sum + number;

    printf("Sum of odd numbers in given range is: %ld",sum);
  
    return 0;

}
Sample output: Enter the minimum range: 1 Enter the maximum range: 100 Sum of odd numbers in given range is: 2500 

+ Report
Total Preview: 823
Sum of odd numbers in c within a range.
Copyright © 2024. Powered by Intellect Software Ltd