当前位置:网站首页>刷题-洛谷-P1307 数字反转
刷题-洛谷-P1307 数字反转
2022-08-04 19:44:00 【宋向上_UP】
P1307 数字反转-C语言
1、题目
2、求解过程
结果:
代码:
//洛谷 1307 数字反转
#include <stdio.h>
#define NUM 10//最多有十位
int main() {
long n;
long m=0;//反转后的数字
int i,j;
int counter=0;//计数器 整数的位数
long position[NUM];//存放每一位的值
scanf("%ld", &n);//输入整数N
while(n!=0){
position[counter] = n % 10;
counter++;//计算位数
n = n / 10;
}
/* printf("counter的值为%d 取出每位的值:\n",counter); for (i = 0; i < counter; i++) { printf(" %ld ", position[i]); } printf("\n");*/
for (i = 0; i < counter-1; i++) {
for (j = 0; j <=i; j++) {
position[j] = position[j] * 10;
}
}
for (i = 0; i < counter; i++) {
m = position[i] + m;
}
printf("%ld", m);
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Use "green computing" technology to promote sustainable development of computing power
zynq records
如何让远在的老板看到你!----------来自财富中国网
Switch node version and switch npm source tool
The difference between Client Side Cache and Server Side Cache
MogDB学习笔记-环境准备及单实例安装
视频目标检测
02 ts 变量定义,类型
量化交易机器人系统开发
awk statistical average max min
lds链接的 顺序问题
nr part calculation
SQL Server 遇到报错解决办法--更新中
JS new一个构造器发生了什么?从零手写一个new方法
图片延迟加载、预加载
To -.-- -..- -
TritonVM——基于Recursive STARK的虚拟机
一些性能测试的要点
zynq 记录
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误