编写函数,函数原型如下:
void fun(int n,char res[]);
函数功能是将整数n的各位数字逆序排列,存放到res字符数组中。
例如整数1035,逆序后为5301
程序测试举例,如输入:
9680200
则输出:
0020869
样例输入:123456
样例输出:654321
#include<stdio.h>
#include<string.h>
void fun(int n, char res[])
{
int i = 0;
while(1)
{
res[i] = n % 10+'0';
printf("%c", res[i]);
i++;
n = n / 10;
if (n == 0)
break;
}
}
int main()
{
int n;
char res[20] = {' '};
scanf_s("%d", &n);
fun(n, res);
return 0;
}