实验3
任务1:
static变量是让变量后面变化的值不受初始定义值的影响。
任务2:
我认为迭代更好,因为简单易懂,递归理解起来不是很容易。
任务3:
任务4:
任务5:
#include <stdio.h> long fun(long s); // 函数声明 int main() { long s, t; printf("Enter a number: "); while (scanf("%ld", &s) != EOF) { t = fun(s); printf("new number is: %ld\n\n", t); printf("Enter a number: "); } return 0; } long fun(long s) { int a,b,c; b=0;c=0; while(s!=0) { a=s%10;s=s/10; if(a%2!=0) { b=b*10+a; } } while(b!=0) { a=b%10;b=b/10; if(a%2!=0) { c=c*10+a; } } return c; }
任务6: