当前位置:网站首页>1101: numbers in reverse order (function topic)
1101: numbers in reverse order (function topic)
2022-07-27 01:35:00 【Rookies also have dreams of entering big factories】
Title Description
Enter a positive integer n, Calculation n In reverse order m, Output m And n And . Ask the program to define a inverse() Function and a main() function ,inverse() Function receives an integer value , Returns the result of the number in reverse order . for example , Given number 7631, The function returns 1367 .
int inverse(int n)
{
// Calculate and return n The reverse number of
}
Input
A positive integer n, The input guarantees that the calculation results are in int Within the scope of .
Output
Output an integer ,n And n The reverse order of the sum of numbers . Output takes up one line .
The sample input Copy
1780
Sample output Copy
2651
See the following for code and details :
#include <stdio.h>
#include <stdlib.h>
int inverse(int n);
int main()
{
int n;
scanf ("%d",&n);
int nn=inverse(n);//nn Is the number in reverse order of the input number
printf ("%d",n+nn); // The sum of the output number itself and the number in reverse order
return 0;
}
int inverse(int n)
{
int i=0;
for (int m=n;m>0;i=i+1) // Judge the length of the input number
{
m=m/10;
}
int s=0;
for (int k=0;k<i;k++)
{
s=s+(int)(n/pow(10,(i-k-1)))*(int)(pow(10,(i-1))/pow(10,(i-k-1)));
//pow The data type is double, Need to be converted to int type ,s Is an inverse ordinal number
int nn=(pow(10,(i-k-1)));
n=n%nn;
}
return s;
}
边栏推荐
猜你喜欢
随机推荐
Summary of heap sorting related knowledge
#MarkDown语法学习总结
Iptables firewall (II)
MQTT协议------上
Introduction to Internet of things platform
ESP8266 STA_ TCP_ Server
Unity CharacterController
Unity Twitter登录接入
5、 Conditional statement of shell
ESP8266 STA_ UDP_ Client
十六、awk
Unity 使用NavMesh实现简易的摇杆功能
Problem feedback: the synchronization of mobile app failed: the external changes of the data warehouse were damaged. The iPad app also downloaded the warehouse as soon as it was opened, and then flash
MakeFile
Navicat操作数据库
C language to realize mine sweeping game:
ESP8266 STA_ Server
c语言实现三子棋游戏
Li Kou brushes 300 record posts
ESP8266连接乐鑫云平台IOT_Demo









![[SQL injection] joint query](/img/82/37008a1ecb4bb37bea42443dbb9be6.png)