#include
#include
int main()
{
int num[1000];
int i;
for (i = 0; i < 1000; i++)
scanf_s("%d", &num[i]);
int len = sizeof(num) / sizeof(num[0]);
int b;
scanf_s("%d", &b);
int temp, temp2;
int c[1000];
int d=1;
if (num[0] < b)
{
temp = num[0] * 10 + num[1];
c[0] = temp / b;
temp2 = temp % b;
for (i = 1; i < len; i++)
{
c[i] =( temp2 * 10 + num[i + 1])/b;
temp2 = (temp2 * 10 + num[i + 1]) %b;
printf("%d", c[i]);
while (i = len - 1)
{
int d = (c[i - 1] * 10 + c[i]) % b;
printf("%d", d);
}
}
}
else
{
c[0] = num[0] / b;
temp2 = num[0] % b;
for (i = 1; i < len; i++)
{
c[i] = (temp2 * 10 + num[i]) / b;
temp2 = (temp2 * 10 + num[i ]) % b;
printf("%d", c[i]);
while (i = len - 1)
{
int d = (c[i - 1] * 10 + c[i]) % b;
printf("%d", d);
}
}
}
return 0;
}
无法正常输出,请问问题出在哪里呢
“Devil组”引证GPT后的撰写:
以下是修改后的代码示例:
#include <stdio.h>
#include <string.h>
int main()
{
char num[1001];
int b;
scanf("%s %d", num, &b);
int len = strlen(num);
int temp = 0, temp2 = 0;
int c[1000];
int i, j;
for (i = 0; i < len; i++) {
temp = temp * 10 + num[i] - '0';
c[i] = temp / b;
temp = temp % b;
}
// 输出商
for (i = 0; i < len; i++) {
if (i == 0 && c[i] == 0) {
continue;
}
printf("%d", c[i]);
}
printf(" ");
// 输出余数
printf("%d\n", temp);
return 0;
}