c语言初初学者求助!

2024-12-03 03:06:29
推荐回答(4个)
回答(1):

printf("tenthousand=%d,thousand=%d,hundred=%d,ten=%d,indiv=%d\n",tenthousand,thousand,hundred,ten,indiv);
中,由于变量是long ,所以printf中控制符号是%ld,长整型输出.改过来就好.

回答(2):

DEV C++ 4.9.9.2 测试过了 没有任何问题

回答(3):

vc++编译通过,没有任何问题啊
你的输出有问题:将里面用到的%d全部改为%ld就没问题了,我试了几个数据成功。
这种问题最好用字符串处理
给你两个程序:
1、(字符串处理型)
#include
#include
#include
#define MAXLEN 12 //定义字符串最大长度,因为用英文表示的最大为hundred billion这里只处理12位以内
void main()
{
char num[MAXLEN+1]; //定义一个字符数组储存输入的数据
int place,i,j,k; //很难想象会有超过37000位的数字,所以只用int类型就够了
printf("Please input an integer!\n"); //提示输入
scanf("%s",num); //输入一个字符串
place=strlen(num); //求出长度即数字所占位数
printf("place=%d!\n",place); //输出位数
k=place; //保存place
for(i=0;i {
if(place==12)
printf("hundredbillion=%c",*(num+i));
else if(place==11)
printf("tenbillion=%c",*(num+i));
else if(place==10)
printf("billion=%c",*(num+i));
else if(place==9)
printf("hundredmillion=%c",*(num+i));
else if(place==8)
printf("tenmillion=%c",*(num+i));
else if(place==7)
printf("million=%c",*(num+i));
else if(place==6)
printf("hundredthousand=%c",*(num+i));
else if(place==5)
printf("tenthousand=%c",*(num+i));
else if(place==4)
printf("thousand=%c",*(num+i));
else if(place==3)
printf("hundred=%c",*(num+i));
else if(place==2)
printf("ten=%c",*(num+i));
else if(place==1)
printf("indiv=%c",*(num+i));
printf("\n");
}
printf("the revers ordinal number is ");
for(place=k,i=place-1;i>=0;i-=1) //反向输出
printf("%c",*(num+i));
printf("\n");
system("pause"); //暂停,防止一闪而过
}

2、(使计算简化):
#include
#include
void main()
{
long place,indiv,ten,hundred,thousand,tenthousand;
long num;
printf("Please input an integer!\n");
scanf("%ld",&num);
place=5;
if(num<=9999) place=4;
if(num<=999) place=3;
if(num<=99) place=2;
if(num<=9) place=1;
printf("place=%ld!\n",place);
tenthousand=num/10000;
thousand=(num/1000)%10; //利用取余来简化计算
hundred=(num/100)%10;
ten=(num/10)%10;
indiv=num%10;
printf("tenthousand=%ld,thousand=%ld,hundred=%ld,ten=%ld,indiv=%ld\n",tenthousand,thousand,hundred,ten,indiv);
printf("the revers ordinal number is ");
switch(place)
{
case 5:printf("%ld%ld%ld%ld%ld\n",indiv,ten,hundred,thousand,tenthousand);break;
case 4:printf("%ld%ld%ld%ld\n",indiv,ten,hundred,thousand);break;
case 3:printf("%ld%ld%ld\n",indiv,ten,hundred);break;
case 2:printf("%ld%ld\n",indiv,ten);break;
case 1:printf("%ld\n",indiv);break;
}
system("pause"); //暂停,防止一闪而过
}

回答(4):

怎么样输都没看到你说的情况