今天来聊聊关于c语言函数调用简单例子,c语言函数调用例子的文章,现在就为大家来简单介绍下c语言函数调用简单例子,c语言函数调用例子,希望对各位小伙伴们有所帮助。
1、举一个用递归调用函数求输入非负整数的阶乘的例子。
2、如下://#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int fact(int n){ if(n==1 || n==0) return 1; else return n*fact(n-1);}int main(void){ int x; while(1){ printf("Input x(int 12>=x>=0)...x="); if(scanf("%d",&x),x>=0 && x<=12)//x>12时会使结果溢出 break; printf("Error,redo: "); } printf("%d! = %d",x,fact(x)); return 0;}。
相信通过c语言函数调用例子这篇文章能帮到你,在和好朋友分享的时候,也欢迎感兴趣小伙伴们一起来探讨。