/ 350
添加表情
遵守中华人民共和国的各项道德法规,承担因您的行为而导致的法律责任,
本站有权保留或删除有争议评论。 参与本评论即表明您已经阅读并接受上述条款。
全部评论 (共 5 条)
学习达人
niuniucty 展开
#include <bits/stdc++.h >
using namespace std;

int main() {
int n,ans=0;
cin >> n;
for (int i = n; i!= 0; i/10) {
int num=i % 10;
ans+=num;
}
cout << ans;
return 0;
}

老师,这个运行,为何没有结果,问题出在哪里
2025年02月11日 09:11
0 回复
T96ueyqd8k 讲师 展开
@ niuniucty for 循环中的更新条件部分写错了。i/10 不会更新变量 i,应该使用 i = i / 10 或者 i /= 10
2025年02月13日 21:11
@TA
laihaiyou 展开
#include<bits/stdc++.h>
using namespace std;

int main() {
int n ;
cin >> n;
for (int i = n ; i != 0 ; i /= 10) {
int num = i % 10;
cout << num ;
}
return 0;
}
老师直接这样倒序可以吗
2024年12月13日 21:11
0 回复
T96ueyqd8k 讲师 展开
@ laihaiyou 运行一下看代码结果呀
2024年12月13日 21:55
@TA
学习达人
T908131xu 展开
#include<bits/stdc++.h>
using namespace std;

int main() {

int a,h,op=0,ko=0;
cin>>a;
int xx=1;
for(int b=a;b!=0;b/=10){
h=b%10;
++op;
}
//得知几位数
--op;

for(int b=a;b!=0;b/=10){
h=b%10;
for(int u=1;u<=op;++u){
xx*=10;
}
ko+=h*xx;
--op;
xx=1;
}
cout<<ko;

return 0;
}
2024年09月05日 20:51
0 回复
T96ueyqd8k 讲师 展开
@ T908131xu 问题是什么呢?
2024年09月06日 21:34
@TA
学习达人
T278539bz 展开
#include <bits/stdc++.h>
using namespace std;

int main(){
   
    int n;
    cin >> n;
    for (;n != 0;n /= 10){
        cout << n % 10;
    }
   
}
老师为什么给我打错了
2024年07月13日 16:38
1 回复
T96ueyqd8k 讲师 展开
@ T278539bz 这段代码是倒序取数,代码没什么问题,但是不是符合作业要求,要检查一下
2024年07月14日 06:59
@TA
学习达人
lichunligxtc 展开
#include<bits/stdc++.h>
using namespace std;
int main(){

int n , cnt=0;
cin >> n;
for(int i = n; i != 0; i /= 10){
int num = i % 10;
++cnt;
cout << num <<" ";
}
cout << "\n" << "n的位数是:" << cnt;

return 0;
}
老师,这个超出了10位的数就出现错误,应该如何修改?
2024年06月18日 14:43
0 回复
T96ueyqd8k 讲师 展开
@ lichunligxtc 由于数据范围的限制,超出10位出现错误是正常的,可以暂时忽略这个问题继续学习,后面会有关于这个问题的答案。
2024年06月18日 20:00
@TA
我的成功之路 更多
V
特惠充值
联系客服
APP下载
官方微信
返回顶部