找错呀!

lvjaio5241 2008-10-18 10:05:41
帮忙找找错误吧!



#include <stdio.h>
#include <math.h>
void main ()
{
long int num;
int indiv,ten,hundred,thousand,ten_thousand,place;
printf ("请输入一个整数(1~99999):");
scanf("%ld",&num);
if (num>9999) place=5;
esle if (num>999) place=4;
esle if (num>99) place=3;
esle if (num>9) place=2;
esle place=1;
printf ("位数=%\n",place);
printf ("每位数字为:");
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv= (int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
switch (place)
{case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d%d\n",indiv,ten,hundren,thousand,ten_thousand);
break;
case 4: printf("%d,%d,%d,%d,",thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d\n",indiv,ten,hundren,thousand);
break;
case 3: printf("%d,%d,%d",hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d\n",indiv,ten,hundren);
break;
case 2: printf("%d,%d",ten,indiv);
printf("\n反序数字:");
printf("%d%d\n",indiv,ten);
break;
case 1: printf("%d",indiv);
printf("\n反序数字:");
printf("%d\n",indiv);
break;
}
}
...全文
95 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wangqiang8848 的回复:]
吉尔这么厉害
[/Quote]
不厉害
[Quote=引用 10 楼 self_control 的回复:]
jill....看到这么长的乱码,你不觉得楼主很不负责么- -!
[/Quote]
他负责不负责不关我事!~o(∩_∩)o...

我就是那天无聊,上来扫了一眼,1楼之后,编译了一下,发现N多问题……

呵呵!~给他上一个小课而已!~相信他以后会明白的……
czbever 2008-10-19
  • 打赏
  • 举报
回复
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv= (int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
要计算得这么烦吗?

这样不就可以了:
ten_thousand=num/10000;
thousand=(num % 10000)/1000;
hundred=(num % 1000)/100;
ten=(num % 100)/10;
indiv= num %10;

hchen2008 2008-10-19
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 self_control 的回复:]
jill....看到这么长的乱码,你不觉得楼主很不负责么- -!
[/Quote]

UP
self_control 2008-10-18
  • 打赏
  • 举报
回复
jill....看到这么长的乱码,你不觉得楼主很不负责么- -!
iceman19860106 2008-10-18
  • 打赏
  • 举报
回复
1.用替换把所有的esle换成else

2.把所有的hundren替换成hundred

wangqiang8848 2008-10-18
  • 打赏
  • 举报
回复
这样更好一些
wangqiang8848 2008-10-18
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <math.h>
int main ()
{
long int num1,num2;
int data[5]={0}; //存储数据的位数
int i=0; //计数器
printf ("请输入一个整数(1~99999):");
scanf("%ld",&num1);
num2=num1;//做个备份


while(num2)
{
data[i]=num2%10;
num2/=10;
i++;
}

printf("每位数字是:");
for(i=4;i>=0;i--)
{
printf("%d ",data[i]);
}
printf("反序输出数据");
for(i=0;i<5;i++)
{
printf("%d ",data[i]);
}


}

wangqiang8848 2008-10-18
  • 打赏
  • 举报
回复
吉尔这么厉害
  • 打赏
  • 举报
回复
#include <stdio.h> 
#include <math.h>
int main ()
{
long int num;
int indiv,ten,hundred,thousand,ten_thousand,place;

printf ("请输入一个整数(1~99999):");
scanf("%ld",&num);
if (num>9999) place=5;
else if(num>999) place=4;//esle if (num>999) place=4;
else if (num>99) place=3;//esle if (num>99) place=3;
else if (num>9) place=2;//esle if (num>9) place=2;
else place=1; //esle place=1;
printf ("位数=%d\n",place); //printf ("位数=%\n",place);
printf ("每位数字为:");
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv= (int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
switch (place)
{
case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,ten_thousand); //printf("%d%d%d%d%d\n",indiv,ten,hundren,thousand,ten_thousand);
break;
case 4: printf("%d,%d,%d,%d,",thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d\n",indiv,ten,hundred,thousand); //printf("%d%d%d%d\n",indiv,ten,hundren,thousand);
break;
case 3: printf("%d,%d,%d",hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d\n",indiv,ten,hundred);//printf("%d%d%d\n",indiv,ten,hundren);
break;
case 2: printf("%d,%d",ten,indiv);
printf("\n反序数字:");
printf("%d%d\n",indiv,ten);
break;
case 1: printf("%d",indiv);
printf("\n反序数字:");
printf("%d\n",indiv);
break;
}
}

刚才居然没贴成功!~郁闷!~

以后自己先编译一下,然后根据错误提示,定位,之后改正错误……
zhxyu19861224 2008-10-18
  • 打赏
  • 举报
回复
printf ("位数=%\n",place);

%d,d好像没有
  • 打赏
  • 举报
回复
执行了一次,发现还有错误!~

以后认真一些哦,最起码得自己编译一下,然后根据错误提示,定位,改正错误……


#include <stdio.h>
#include <math.h>
int main ()
{
long int num;
int indiv,ten,hundred,thousand,ten_thousand,place;

printf ("请输入一个整数(1~99999):");
scanf("%ld",&num);
if (num>9999) place=5;
else if(num>999) place=4;//esle if (num>999) place=4;
else if (num>99) place=3;//esle if (num>99) place=3;
else if (num>9) place=2;//esle if (num>9) place=2;
else place=1; //esle place=1;
printf ("位数=%d\n",place); //printf ("位数=%\n",place);
printf ("每位数字为:");
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv= (int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
switch (place)
{
case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,ten_thousand); //printf("%d%d%d%d%d\n",indiv,ten,hundren,thousand,ten_thousand);
break;
case 4: printf("%d,%d,%d,%d,",thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d\n",indiv,ten,hundred,thousand); //printf("%d%d%d%d\n",indiv,ten,hundren,thousand);
break;
case 3: printf("%d,%d,%d",hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d\n",indiv,ten,hundred);//printf("%d%d%d\n",indiv,ten,hundren);
break;
case 2: printf("%d,%d",ten,indiv);
printf("\n反序数字:");
printf("%d%d\n",indiv,ten);
break;
case 1: printf("%d",indiv);
printf("\n反序数字:");
printf("%d\n",indiv);
break;
}
}
  • 打赏
  • 举报
回复
太不认真了!~

else

还有变量

格式自己调整吧!~养成良好的编程习惯

#include <stdio.h>
#include <math.h>
int main ()
{
long int num;
int indiv,ten,hundred,thousand,ten_thousand,place;

printf ("请输入一个整数(1~99999):");
scanf("%ld",&num);
if (num>9999) place=5;
else if(num>999) place=4;//esle if (num>999) place=4;
else if (num>99) place=3;//esle if (num>99) place=3;
else if (num>9) place=2;//esle if (num>9) place=2;
else place=1; //esle place=1;
printf ("位数=%\n",place);
printf ("每位数字为:");
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv= (int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
switch (place)
{case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,ten_thousand); //printf("%d%d%d%d%d\n",indiv,ten,hundren,thousand,ten_thousand);
break;
case 4: printf("%d,%d,%d,%d,",thousand,hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d%d\n",indiv,ten,hundred,thousand); //printf("%d%d%d%d\n",indiv,ten,hundren,thousand);
break;
case 3: printf("%d,%d,%d",hundred,ten,indiv);
printf("\n反序数字:");
printf("%d%d%d\n",indiv,ten,hundred);//printf("%d%d%d\n",indiv,ten,hundren);
break;
case 2: printf("%d,%d",ten,indiv);
printf("\n反序数字:");
printf("%d%d\n",indiv,ten);
break;
case 1: printf("%d",indiv);
printf("\n反序数字:");
printf("%d\n",indiv);
break;
}
}
  • 打赏
  • 举报
回复
先编译看看,能不能通过……

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧