c++问题一道,希望有简单写法,谢谢

[复制链接]
查看11 | 回复2 | 2009-11-7 11:43:37 | 显示全部楼层 |阅读模式
能,可以先定义一个数组,然后把各位数字都分离出来。再按数组的元素输出就OK了!郑州今迈网络部!大致写一下:int a=4571; int array[];array[1]=a%1000%100%10;array[2]=a%1000/100;array[3]=a%100/10;array[4]=a%10;printf就行了。就个FOR循环会提高算法的质量!
回复

使用道具 举报

千问 | 2009-11-7 11:43:37 | 显示全部楼层
include int main() { int x,i,j,n=0; int a[5];scanf("%d",&x); while(x!=0){ a=x%10;x=x/10;i++;} cout>x; while(x!=0){ {a=x%10;
x=x/10;}
i++;} coutusing namespace std; void main() { int len; char a[5]; cout>a;
len=strlen(a); cout=0;i--){ cout#include using namespace std;void fun(int);// 实现整个功能的函数int main(){
int a = 4571;
fun(a);
return 0;}void fun(int a){int temp = a,len = 1,ar = 0;while (temp >= 10){ temp /= 10; len++;}cout >a;while(a!=0){b=a%10; n++;cout<<n<<b;a=a/10;}}
回复

使用道具 举报

千问 | 2009-11-7 11:43:37 | 显示全部楼层
利用string 1,判断整数长度(可以用for语句加假如减去9999不小于零说明是万级,再减999这样做下来来个循环可以判断位数)2,然后将分解的数字存入数组string,然后正反输出就随便你了...呵呵不是很麻烦的自己写写看提供思路给你
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行