1、C语言函数练习题 /*姓名:白银日期:描述:英尺,英寸,米,厘米之间的转换*/#include float GetInch(float feet);float GetMeter(float inch);float GetCentiMeter(float meter);void main()float inch;float meter;float centimeter;float feet;printf(请输入英尺的值n);scanf(%f,&feet);inch=GetInch(feet);printf(转换成英寸的结果是%.2f:,inch);printf(n);meter=GetMeter
2、(GetInch(feet);printf(转换成米的结果是%.2f:,meter);printf(n);centimeter=GetCentiMeter(GetMeter(GetInch(feet);printf(转换成米的结果是%.2f:,centimeter);printf(n);float GetInch(float feet)float inch;inch=feet*12;return inch;float GetMeter(float inch)float meter;meter=inch*;return meter;float GetCentiMeter(float meter)
3、float centimeter;centimeter=meter*100;return centimeter;/*姓名:白银日期:描述:底和高求三角形面积*/#include float GetArea(float h,float l);void main()float area;float h;float l;printf(请输入底和高n);scanf(%f,%f,&l,&h);area=GetArea(h,l);printf(三角形面积=%.2f,area);printf(n);float GetArea(float h,float l)float area;area=h*l/2;ret
4、urn area;/*姓名:白银日期:描述:函数递归求阶乘*/#include int GetFactorial(int number);void main()int number;unsigned long int result;printf(请输入number的值n);scanf(%d,&number);result=GetFactorial(number);printf(结果是%dn,result);int GetFactorial(int number)int result;if(number=1)result=1;elseresult=GetFactorial(number-1)*n
5、umber;return result;/*姓名:白银日期:描述:画出一个正方形*/#include void Draw(int num);void OutPut1(int num);void OutPut2(int num);void main()int num;printf(请输入正方型的行数n);scanf(%d,&num);Draw(num);printf(n);void OutPut1(int num)int i;for(i=0;inum;i+)printf(*);for(i=0;inum;i+)printf(n);void OutPut2(int num)int i;for(i=0
6、;inum;i+)printf(n);for(i=0;inum;i+)printf(*);void Draw(int num)int i;int j;OutPut1(num);for(i=0;inum;i+)for(j=0;jnum;j+)if(i=0&j=0)|(i=(num-1)&j=0)|(i=(num-1)&j=(num-1)|(i=0&j=(num-1)printf(*);elseprintf( );printf(n);OutPut2(num);/*姓名:白银日期:描述:求出3个数字的立方的和*/#include #include float GetNumber(float a,fl
7、oat b,float c);void main()float a,b,c;float num;printf(请输入3个数字n);scanf(%f%f%f,&a,&b,&c);num=GetNumber(a,b,c);printf(结果=%.2fn,num);float GetNumber(float a,float b,float c)float num;num=(float) (pow(a,3)+pow(b,3)+pow(c,3);return num;/*作者:白银日期:描述:输入一定的钱数,得出最少需要多少张*/#include int GetMoney(int *num,int mo
8、ney);void main()int a7;int *p;int num;p=#printf(请输入钱数n);scanf(%d,p);a0=GetMoney(p,100);a1=GetMoney(p,50);a2=GetMoney(p,20);a3=GetMoney(p,10);a4=GetMoney(p,5);a5=GetMoney(p,2);a6=GetMoney(p,1);printf(需要100元的%d张n,a0);printf(需要50元的%d张n,a1);printf(需要20元的%d张n,a2);printf(需要10元的%d张n,a3);printf(需要5元的%d张
9、n,a4);printf(需要2元的%d张n,a5);printf(需要1元的%d张n,a6);int GetMoney(int *num,int money)int count;count=*num/money;*num=*num%money;return count;/*作者:白银日期:2007,6,11描述:输入一个数转换成16,2,12,7,8进制的数字,并且输出。*/#include void GetSixteen(int num);入成绩n2.成绩排序n3.成绩输出n4.退出);printf(n*n);scanf(%d,&b);if(b=1)num=InPut(a);printf(
10、学员总数是%d,num);else if(b=2)Sort(a,num);else if(b=3)OutPut(a,num);int InPut(int *a)int i;printf(请输入学员的成绩(00为退出输入)n);for(i=0;iN;i+)scanf(%d,a+i);if(*(a+i)=00)break;return i;void OutPut(int *a,int num)int i;printf(成绩输出n);for(i=0;inum;i+)printf(%d ,*(a+i);printf(n);void Sort(int *a,int num)int i;int j;int temp;for(i=0;inum-1;i+)for(j=0;j*(a+j+1)temp=*(a+j);*(a+j)=*(a+j+1);*(a+j+1)=temp;printf(排序完成n);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1