Answer to Question #242129 in C for Kelly

Question #242129

Write a program that display the sum of all odd numbers between a and b (inclusive). Where a and b are inputs from the user.


Thank you.


1
Expert's answer
2021-09-25T10:04:22-0400
#include <stdio.h>


int main()
{
    int a,b;
    printf("\nEnter the start number:");
    scanf("%d",&a);
    printf("\nEnter the stop number:");
    scanf("%d",&b);
    
    int sum=0;
    for(int i=a;i<=b;i++){
        if (i%2 !=0)
            sum+=i;
    }
    printf("The sum of numbers between %d and %d inclusive = %d",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
APPROVED BY CLIENTS