Given two integers A and B, output all integers from A to B and the sum of these numbers.
Input format:
The input gives 2 integers A and B in one line, where −100≤A≤B≤100, separated by spaces.
Output format:
First, all integers from A to B are sequentially output, each 5 digits occupy one line, each digit occupies 5 characters width, and is aligned to the right. Finally, the sum X of all numbers is output in the format of Sum = X in one line.
Sample input:
-3 8
Sample output:
-3 -2 -1 0 1
2 3 4 5 6
7 8
Sum = 30
Others' reference answers
#include<stdio.h>
int main()
{
int a,b,i,cot=0,sum=0;
scanf("%d %d",&a,&b);
for(i=a;i<=b;i++)
{
printf("%5d",i);//题目要求占5个字符宽
cot++;
if(cot%5==0&&i!=b)
printf("\n");
}
printf("\n");//执行完循环后,换行输入总和
for(i=a;i<=b;i++)
sum+=i;
printf("Sum = %d",sum);
return 0;
}
Wrong answer
As a result, because it cannot be established here, there is no way to modify it for a long time, only Baidu.
After the modification, the answer is the same, and it is still wrong, very embarrassing.