摘要: 1 /*函数的递归调用*/ 2 #include 3 int age(int n); 4 int main(void) 5 { 6 printf("%d\n",age(5)); 7 return 0; 8 } 9 int age(int n)10 {11 int r;12 if(n==1)13 {14 return 10;15 }16 else 17 {18 r=age(n-1) + 2;19 }20 return (r);21 }22 阅读全文
posted @ 2013-11-07 22:09 ASMLearner 阅读(855) 评论(0) 推荐(0) 编辑
摘要: 1 /*函数嵌套调用*/ 2 #include 3 float dif(float x,float y,float z); 4 float max(float x,float y,float z); 5 float min(float x,float y,float z); 6 int main(void) 7 { 8 float a,b,c,r; 9 printf("Please input three numbers:\n");10 scanf("%f%f%f",&a,&b,&c);11 r=max(a,b,c);12 pri 阅读全文
posted @ 2013-11-07 21:22 ASMLearner 阅读(537) 评论(0) 推荐(0) 编辑
摘要: 1 /*被调用函数出现在主调用函数之前*/ 2 #include 3 float cube(float x); 4 int main(void) 5 { 6 float a,product; 7 printf("Please input value of a:\n"); 8 scanf("%f",&a); 9 product=cube(a);10 printf("Cube of %.4f is %.4f\n",a,product);11 return 0;12 }13 float cube(float x)14 {15 flo 阅读全文
posted @ 2013-11-07 20:53 ASMLearner 阅读(415) 评论(0) 推荐(0) 编辑
摘要: 1 /*自定义函数:两数相加*/ 2 #include 3 float add(float x,float y); 4 int main(void) 5 { 6 float i,j,num; 7 printf("please input two numbers:\n"); 8 scanf("%f%f",&i,&j); 9 num=add(i,j);10 printf("The SUM of your inputed is: %.2f\n",num);11 return 0;12 }13 float add(float 阅读全文
posted @ 2013-11-07 20:36 ASMLearner 阅读(458) 评论(0) 推荐(0) 编辑
摘要: 1 /*自定义函数求两个数最大数*/ 2 #include 3 int max(int x,int y); 4 int main(void) 5 { 6 int a,b,c; 7 printf("Please input two integer numbers:\n"); 8 scanf("%d%d",&a,&b); 9 c=max(a,b);10 printf("the largest number is: %d\n",c);11 return 0;12 }13 int max(int x,int y)14 {15 阅读全文
posted @ 2013-11-07 01:59 ASMLearner 阅读(589) 评论(0) 推荐(0) 编辑
摘要: 1 /*交换一组数据的位置*/ 2 #include 3 int main(void) 4 { 5 int a[6],i,j,m,n,temp=0; 6 printf("Please input number:\n"); 7 scanf("%d",&j); 8 printf("Please input %d integer numbers:\n",j); 9 for (i=0;i<j;i++)10 {11 scanf("%d",&a[i]);12 }13 m=j/2;14 for(i=0;i& 阅读全文
posted @ 2013-11-07 01:42 ASMLearner 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 1 /*输出十行杨辉三角形*/ 2 #define N 10 3 #include 4 int main(void) 5 { 6 int s[N][N],i,j; 7 for(i=0;i<=N;i++) 8 { 9 s[i][i]=1;10 s[i][0]=1;11 }12 for(i=2;i<N;i++)13 for(j=1;j<i;j++)14 s[i][j]=s[i-1][j-1]+s[i-1][j];15 for (i=0;i<N;i++)16 { f... 阅读全文
posted @ 2013-11-07 00:55 ASMLearner 阅读(483) 评论(0) 推荐(0) 编辑