《C语言程序设计函数练习题及参考答案》由会员分享,可在线阅读,更多相关《C语言程序设计函数练习题及参考答案(60页珍藏版)》请在人人文库网上搜索。
1、C语言程序设计练习题及参考答案 1、定义一个函数int fun(int a,int b,int c),它的功能是:若a,b,c能构成等边三角形函数返回3,若能构成等腰三角形函数返回2,若能构成一般三角形函数返回1,若不能构成三角形函数返回0。 #include int fun(int a,int b,int c) if(a+bc & b+ca & a+cb) if(a=b & b=c ) return 3; else if(a=b|b=c|a=c) return 2; else return 1; else return 0; void main() int a,b,c,shape; prin。
2、tf(Input a,b,c: ); scanf(%d%d%d,&a,&b,&c); printf(a=%d, b=%d, c=%dn,a,b,c); shape =fun(a,b,c); printf(nThe shape : %dn,shape); ;. . 2、编写一个程序,将两个变量的值交换, 例如变量a中的值原为 3,b中的值原为8,程序运行后 a 中的值为8,b中的值为3。 #include void fun(int *x,int *y) int t; t=*x;*x=*y;*y=t void main() int a=3,b=8; printf(%d %dn,a,b); fun(。
3、&a,b); printf(%d %dn,a,b); ;. . 3、从键盘输入3个数,将最大值放在变量a中,最小值放在变量c中。 例如,输入的数为:55 12 34, 输出结果应当是:a=55.0,b=34.0,c=12.0。 #include void fun(float *p,float *q,float *s) float k; if (*p #include int fun(int n) int i,s=0; for (i=2;i #include float fun(int n) int i; float s=1.0,h=1; for (i=2;i void fun(long s,l。
4、ong *t) int d; long s1=1; *t=0; while (s0) d=s_x0010_; if(d%2!=0) *t=d*s1+*t; s1=s1*10; s/=