输入若个正整数,输入0停止,将这些整数按顺序构造为一个新的整数。假设新的整数不超出整数的最大范围。
例如:输入:74
3
904
0
输出:743904
#include <math.h>
int main()
{
int n;
int acc = 0;
while (true)
{
scanf("%d", &n);
if (n == 0) break;
acc *= (int)pow((double)10, (int)(log10((double)n) + 1));
acc += n;
}
printf("%d\n", acc);
}
运行通过
123
45
6
0
123456
Press any key to continue . . .
楼上正确,是比较简单的一个了
既然没涉及到运算,不明白为什么要有个不超过整型范围的约束。
输入n个数字,可以以字符串读入,然后strcat连接起来,最后输出即可。
或者输入n个int,保存,然后紧挨着输出,最后换行就行了。
可以用字符串接受,然后拼接字符串直接输出就好了,反正又不用坐运算。
直接作为字符串接收,然后拼接字符串是最简单的
用字符串接受 一个一个输 反正程序比较简单 这样也是可以滴
#include
void main(){
int num[100]={0};
int top=0;
int temp;
int i;
while(1){// 输入若干个数
scanf("%d",&temp);
if(temp==0) break;
num[top]=temp;
top++;
}
for(i=0;i<top;i++){ //顺序输出
printf("%d",num[i]);
}
}