# 大家帮着改个程序吧 。。。。

zhang4665032 2008-04-14 02:18:08
#include <iostream>

int main()
{int f();
long n,a,b,c,d,e;
float x;
std::cout<<"输入一个不多于5位的正整数n："<<std::endl;
std::cin>>n;
{if(n<0)
std::cout<<"请输入正整数："<<std::endl;

}

x=(double)(n/10000);
if(x>=1)
{
std::cout<<"此数是个五位数:"<<std::endl;

}
else if(x>=1/10)
{
std::cout<<"此数是个四位数"<<std::endl;
}
else if(x>=1/100)
{
std::cout<<"此次数是个三位数:"<<std::endl;

}
else if(x>=1/1000)
{
std::cout<<"此数是个两位数:"<<std::endl;

}
else
{
std::cout<<"此数是个一位数"<<std::endl;

}
a=n/10000;
b=(n-a*10000)/1000;
c=(n-a*10000-b*1000)/100;
d=(n-a*10000-b*1000-c*100)/10;
e=n-a*10000-b*1000-c*100-d*10;

std::cout<<"万位是:"<<a<<std::endl;

std::cout<<"千位是:"<<b<<std::endl;

std::cout<<"百位是:"<<c<<std::endl;

std::cout<<"十位是:"<<d<<std::endl;

std::cout<<"个位是:"<<e<<std::endl;

return 0;
}

...全文
68 8 打赏 收藏 转发到动态 举报

8 条回复

baihacker 2008-04-14
• 打赏
• 举报

``````
do{
std::cout <<"输入一个不多于5位的正整数n：" <<std::endl;
std::cin>>n;
if(n <0)
std::cout <<"请输入正整数：" <<std::endl;
else
break;
} while(true);
``````
zhang4665032 2008-04-14
• 打赏
• 举报

xuhongshan 2008-04-14
• 打赏
• 举报

kevinchj 2008-04-14
• 打赏
• 举报

kevinchj 2008-04-14
• 打赏
• 举报

c_spark 2008-04-14
• 打赏
• 举报

ls挺快啊
c_spark 2008-04-14
• 打赏
• 举报

``````#include   <iostream>

int main()
{int f();
long n,a,b,c,d,e;
float x;
std::cout <<"输入一个不多于5位的正整数n：" <<std::endl;
std::cin>>n;
{if(n <0)
std::cout <<"请输入正整数：" <<std::endl;

}

x=(double)(n*1.0/10000);
printf("%lf\n",x);
if(x>=1)
{
std::cout <<"此数是个五位数:" <<std::endl;

}
else if(x>=1.0/10)
{
std::cout <<"此数是个四位数" <<std::endl;
}
else if(x>=1.0/100)
{
std::cout <<"此次数是个三位数:" <<std::endl;

}
else if(x>=1.0/1000)
{
std::cout <<"此数是个两位数:" <<std::endl;

}
else
{
std::cout <<"此数是个一位数" <<std::endl;

}
a=n/10000;
b=(n-a*10000)/1000;
c=(n-a*10000-b*1000)/100;
d=(n-a*10000-b*1000-c*100)/10;
e=n-a*10000-b*1000-c*100-d*10;

std::cout <<"万位是:" <<a <<std::endl;

std::cout <<"千位是:" <<b <<std::endl;

std::cout <<"百位是:" <<c <<std::endl;

std::cout <<"十位是:" <<d <<std::endl;

std::cout <<"个位是:" <<e <<std::endl;

return 0;
} ``````
baihacker 2008-04-14
• 打赏
• 举报

``````
#include   <iostream>

int main()
{
int f();
long n,a,b,c,d,e;
float x;
std::cout <<"输入一个不多于5位的正整数n：" <<std::endl;
std::cin>>n;
{
if(n <0)
std::cout <<"请输入正整数：" <<std::endl;

}

x=(double)(1.0*n/10000);  //把很多1改成1.0了(后面还有),注意浮点数和整数的除法!!!
if(x>=1)
{
std::cout <<"此数是个五位数:" <<std::endl;
}
else if(x>=1.0/10)
{
std::cout <<"此数是个四位数" <<std::endl;
}
else if(x>=1.0/100)
{
std::cout <<"此次数是个三位数:" <<std::endl;

}
else if(x>=1.0/1000)
{
std::cout <<"此数是个两位数:" <<std::endl;

}
else
{
std::cout <<"此数是个一位数" <<std::endl;

}
a=n/10000;
b=(n-a*10000)/1000;
c=(n-a*10000-b*1000)/100;
d=(n-a*10000-b*1000-c*100)/10;
e=n-a*10000-b*1000-c*100-d*10;
std::cout <<"万位是:" <<a <<std::endl;
std::cout <<"千位是:" <<b <<std::endl;
std::cout <<"百位是:" <<c <<std::endl;
std::cout <<"十位是:" <<d <<std::endl;
std::cout <<"个位是:" <<e <<std::endl;

return 0;
}

``````

64,701

c++ 技术论坛（原bbs）

• 近7日
• 近30日
• 至今

1. 请不要发布与C++技术无关的贴子
2. 请不要发布与技术无关的招聘、广告的帖子
3. 请尽可能的描述清楚你的问题，如果涉及到代码请尽可能的格式化一下