1、do语句;
#include <stdio.h>
int main(void)
{
int a, b, min, max, sum = 0;
puts("please input two integers.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
if (a > b)
{
min = b;
max = a;
}
else
{
min = a;
max = b;
}
do
{
sum += min;
min++;
}
while (min <= max);
printf("sum = %d\n", sum);
return 0;
}
或者
#include <stdio.h>
int main(void)
{
int a, b, min, max, sum = 0;
puts("please input two integers.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
min = a > b ? b:a;
max = a > b ? a:b;
do
{
sum += min;
min++;
}
while (min <= max);
printf("sum = %d\n", sum);
return 0;
}
2、while语句;
#include <stdio.h>
int main(void)
{
int a, b, min, max, sum = 0;
puts("please input two integers.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
min = a > b ? b:a;
max = a > b ? a:b;
while (min <= max)
{
sum += min;
min++;
}
printf("sum = %d\n", sum);
return 0;
}
3、for语句
#include <stdio.h>
int main(void)
{
int a, b, min, max, sum = 0;
puts("please input two integers.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
min = a > b ? b:a;
max = a > b ? a:b;
for (min; min <= max; min++)
{
sum += min;
}
printf("sum = %d\n", sum);
return 0;
}
————————————————————————————————————————————————————————————————————————————————————————————————————
————————————————————————————————————————————————————————————————————————————————————————————————————
1、do语句
#include <stdio.h>
int main(void)
{
int i, j, min, max, sum = 0;
puts("please input two integer.");
printf("i = "); scanf("%d", &i);
printf("j = "); scanf("%d", &j);
if ( i > j)
{
max = i;
min = j;
}
else
{
max = j;
min = i;
}
do
{
sum += min;
min++;
}
while (min <= max);
printf("sum = %d\n", sum);
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i, j, max, min, sum = 0;
puts("please input two integers.");
printf("i = "); scanf("%d", &i);
printf("j = "); scanf("%d", &j);
max = i > j ? i:j;
min = i > j ? j:i;
do
{
sum += min;
min++;
}
while (min <= max);
printf("sum = %d\n", sum);
return 0;
}
2、while语句
#include <stdio.h>
int main(void)
{
int i, j, max, min, sum = 0;
puts("please input two integers.");
printf("i = "); scanf("%d", &i);
printf("j = "); scanf("%d", &j);
if (i > j)
{
max = i;
min = j;
}
else
{
max = j;
min = i;
}
while (min <= max)
{
sum += min;
min++;
}
printf("sum = %d\n", sum);
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i, j, max, min, sum = 0;
puts("please input two integers.");
printf("i = "); scanf("%d", &i);
printf("j = "); scanf("%d", &j);
max = i > j ? i:j;
min = i > j ? j:i;
while (min <= max)
{
sum += min;
min++;
}
printf("sum = %d\n", sum);
return 0;
}
3、for语句
#include <stdio.h>
int main(void)
{
int i, j, max, min, sum = 0;
puts("please input two integers.");
printf("i = "); scanf("%d", &i);
printf("j = "); scanf("%d", &j);
if (i > j)
{
max = i;
min = j;
}
else
{
max = j;
min = i;
}
for (min; min <= max; min++)
{
sum += min;
}
printf("sum = %d\n", sum);
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int i, j, max, min, sum = 0;
puts("please input two integers.");
printf("i = "); scanf("%d", &i);
printf("j = "); scanf("%d", &j);
max = i > j ? i:j;
min = i > j ? j:i;
for (min; min <= max; min++)
{
sum += min;
}
printf("sum = %d\n", sum);
return 0;
}