输入一个字符串,倒序输出:
#include <stdio.h>
int main()
{
char *ch;
char a;
int i = 0;
char b[100];
char *p = b;
puts("输入字符倒叙输出,输入'#'结束:");
while(scanf("%c",p)&&(*p != '#'))
{
p++;
i++;
}
for(i;i>0;i--)
{
p--;
printf("%c",*p);
}
printf("\n");
return 0;
}
输入任意位的正数,倒序输出:
#include <stdio.h>
int main()
{
unsigned int num;
unsigned int tmp = 0;
unsigned int result = 0;
scanf("%ul",&num);
while(num)
{
tmp = num%10;
num /= 10;
result = result*10+tmp;
}
printf("result = %ul\n",result);
return 0;
}
将一个数组逆序放到原来数组中。
void reverse(int *p, int length)
{
int n = length / 2;
for(int i=0;i<n;i++)
{
int tmp = *(p + i);
*(p + i) = *(p + length - 1 - i);
*(p + length - 1 - i) = tmp;
}
}