小白教程

 找回密码
 立即注册
查看: 7946|回复: 2

c语言输出一个三位数的逆数

[复制链接]

1

主题

2

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2021-5-3 09:30:35 | 显示全部楼层 |阅读模式

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

1

主题

2

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2021-5-12 04:29:21 | 显示全部楼层
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int a,b,c;
  5.     int m,n;
  6.     scanf("%d",&m);
  7.     a=m/100;
  8.     b=(m-a*100)/10;
  9.     c=m-100*a-10*b;
  10.     n=c*100+b*10+a;
  11.     printf("%d",n);
  12.     return 0;
  13. }
复制代码

刚开始学时的版本
回复

使用道具 举报

0

主题

1

帖子

2

积分

新手上路

Rank: 1

积分
2
发表于 2021-5-25 22:58:57 | 显示全部楼层
  1. #include <stdio.h>

  2. void reverse_num(int num);
  3. int main(void)
  4. {
  5.     reverse_num(123);
  6.     putchar(10);
  7.     return 0;
  8. }

  9. void reverse_num(int num)
  10. {
  11.     if (num == 0)
  12.         return;

  13.     printf("%d", num%10);
  14.     reverse_num(num / 10);
  15. }
复制代码

供参考~
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|小白教程 ( 粤ICP备20019910号 )

GMT+8, 2024-9-20 12:34 , Processed in 0.032496 second(s), 25 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】

快速回复 返回顶部 返回列表