Answer to Question #238822 in C for Woyengimiesindo Ma

Question #238822
The sum of all odd numbers between a and b (inclusive), where a and b are inputs
1
Expert's answer
2021-09-20T05:48:20-0400
#include <stdio.h>

int main() {
    int a, b, sum, i;

    printf("Enter a: ");
    scanf("%d", &a);
    printf("Enter b: ");
    scanf("%d", &b);

    sum = 0;
    for (i=a; i<=b; i++) {
        if (i%2 == 1) {
            sum += i;
        }
    }
    printf("The sum of odd numbers between %d and %d is %d.\n",
            a, b, sum);
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS