/*Write a C program to print
the numbers from the lowest
to the highest (inclusive)
and the sum of consecutive
integers from a given pair
of numbers.
Test Data :
Input a pair of numbers (for
example 10,2):
Input first number of the
pair: 10
Input second number of the
pair: 2
Expected Output:
List of odd numbers: 3
5
7
9
Sum=24
*/
#include <stdio.h>
int main()
{
int num1,num2,i,sum=0;
printf("Input a pair of\
\nnumber (for example 10,2):\
\n");
printf("Input first number\
of the pair: ");
scanf("%d",&num1);
printf("Input second number\
of the pair: ");
scanf("%d",&num2);
if(num1<num2)
{
return printf("Please try\
again.\n");
}
printf("List of odd number:\
\n");
for(i=num2;i<num1;i++)
{
if(i%2!=0)
{
printf("%d\n",i);
sum=sum+i;
}
}
printf("Sum=%d\n",sum);
return 0;
}
No comments:
Post a Comment