Q.C Program - Accept two integers x and y and calculate the sum of all integers between x and y (both inclusive)
Program
#include <stdio.h>
void main(void)
{
int a = 1;
int b = 0;
int total_sum = 0;
while (a > b)
{
printf("The second number should be bigger than the first one.\n");
printf("Type the first number : \n");
scanf("%d", &a);
printf("Type the second number : \n");
scanf("%d", &b);
}
while (a<= b)
{
total_sum += a;
a++;
}
printf("Result : %d\n", total_sum);
}
Output:
The second number should be bigger than the first one.
Type the first number :
5
Type the second number :
9
Result : 35
Program
#include <stdio.h>
void main(void)
{
int a = 1;
int b = 0;
int total_sum = 0;
while (a > b)
{
printf("The second number should be bigger than the first one.\n");
printf("Type the first number : \n");
scanf("%d", &a);
printf("Type the second number : \n");
scanf("%d", &b);
}
while (a<= b)
{
total_sum += a;
a++;
}
printf("Result : %d\n", total_sum);
}
Output:
The second number should be bigger than the first one.
Type the first number :
5
Type the second number :
9
Result : 35
0 Comments