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.
#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;
}
Comments
Leave a comment