参考方法:
#include<stdio.h> int age(int n) { if(n == 1) return 10; else return age(n - 1) + 2; } int main(void) { int n; n = age(5); printf("%d\n",n); return 0; }
#include <stdio.h> int main() { int x1 = 10, x2, x3, i; for (i=0; i < 4; i++) { x2 =x1 + 2; x1 = x2; } printf ("%d",x2); return 0; }
/* * * 题目:利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。 * * */ #include<stdio.h> #include<string.h> int reverse(int num, char* chr) { int head = 0,tail = num - 1; int counter = num / 2; counter--; if(counter < 0) return 0; else { *(chr + head) ^= *(chr + tail); *(chr + tail) ^= *(chr + head); *(chr + head) ^= *(chr + tail); } return reverse(num - 2,chr + 1 ); } int main() { char buf[6] = {0}; printf("请输入5个字符:"); fgets(buf, 6, stdin); reverse(strlen(buf),buf); printf("倒叙输出结果为:%s\n\n",buf); return 0; }
#include<stdio.h> void Print(char a[], int n) { if(n >= 0) { printf("%c",a[n]); Print(a,n - 1); } } int main(void) { char a[5]; printf("请输入5个字符 :"); for(int i = 0; i < 5; i++) scanf("%c",&a[i]); printf("相反顺序输出结果 : "); Print(a,4); return 0; }
#include <stdio.h> void f() { char ch; if((ch=getchar())!='\n') { f(); } if(ch!='\n') { printf("%c",ch); } } void main() { printf("请输入字符: "); f(); }
感谢您的支持,我会继续努力的!
支付宝扫一扫,即可进行扫码打赏哦
1755c-exercise-example28
参考方法:
1754c-exercise-example28
参考方法:
1753c-exercise-example27
1752c-exercise-example27
参考方法:
1751c-exercise-example27
参考方法: