首页 > 编程语言 > 详细

自己第一次写的关于判断正整数位数及输出各位数的数的C++代码。

时间:2020-03-15 15:29:56      阅读:100      评论:0      收藏:0      [点我收藏+]

#include <iostream>
#include <cmath>
using namespace std;
int main() {
int x, y, z;
y = 10;
cout<< "请输入一个正整数:" << endl;
cin >> x;
int n = 1;
for (; n < 10; n++) {
if (x / int((pow(y, n))) == 0) { //用到了幂运算函数pow,返回的值是double型就又int,
break;
}
}
cout << "该整数的位数为:" << n << endl;
if (n == 1) {
cout << (x % 10) << " ";
}
if (n == 2) {
cout << (x % 10) << " ";
cout << (x / 10 ) << " ";
}
int i = 2;
if (n > 2) {
cout << (x % 10) << " " ;
cout << (x / 10 % 10) << " ";
for (; i < n; i++) {
cout << (x / int((pow(y, i))))%10 << " ";
}
}
return 0;
}

自己第一次写的关于判断正整数位数及输出各位数的数的C++代码。

原文:https://www.cnblogs.com/-HXF-/p/12497501.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!