1.输入一个无符号整数,从后往前分别打印它每位的数,如输入1234,输出4 3 2 1
#include<stdio.h>
void print(int n)
{
printf("%2d",n%10);
if(n>9)
{
print(n/10);
}
}
int main()
{
int num = 0;
scanf("%d",&num);
print(num);
return 0;
}
2.计算n的阶乘
#include<stdio.h>
int test( int num)
{
int re = 1;
if(num > 0)
re=num*test(num -1);
return re;
}
int main()
{
int n = 0;
int res = 0;
scanf("%d",&n);
res = test(n);
printf("%d\n",res);
return 0;
}
3.统计字符数
#include <stdio.h>
int test(char *str)
{
int res = 0;
if(*str !='\0')
res = 1+test(str+1);
return res;
}
int main()
{
char arr[1000];
int n = 0;
gets(arr);
n = test(arr);
printf("字符数等于%d",n);
return 0;
}