栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

水题-逆序输出

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

水题-逆序输出

 1.将数字进行/10,重复n次  直到数字最后为0  此时n就是数字的位数

2.将数字/10^(位数-1)%10  例如1233/1^(4-1)%10=1233/1000%10=1;1233/100%10=2;....

3.将数字进行分解 个位*10^(位数-1)+十位*10(位数-1)...直到最高位

#include
using namespace std;
#include
void getNumFigureArr(int num,int len);

int getNumlen(int num){
    int len;
    
    for(len=0;num!=0;len++){
        num=num/10;
    }
    cout<<"The number of digits of this number";
    cout<>arr;
    while(strlen(arr)>5){//如果输入位数大于5  提示输入错误请重新输入
        cin>>arr;
    }
    //arr数组的长度就是这个数的长度
    cout<<"The number of digits of this number";
    cout<num;
    //获取数字长度
    int len=getNumlen(num);
    //获取每一位数字
    getNumFigure(num,len);
    //根据数字和数据长度  对输入的数字进行逆序输出
    reverseNum(num,len);

    //利用数组的方法 记录正序的每一位数字 然后再逆序输出---------------------------------------------
    //getNumFigureArr(num,len);

    return 0;
}



void getNumFigureArr(int num,int len){
    int arr[10];
    
    int i;
    int thislen=len;
    for(i=1;len!=1;len--){
        i=i*10;
    }
    
    cout<<"Every digit of this number"<=0;i--,pow=pow/10){
        newNum=newNum+arr[i]*pow;
    }
    cout<<"This number is printed in reverse order : ";
    cout< 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/311965.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号