计算机程序设计基础(c语言) 习题 编程题
计算机程序设计基础(C语言)
编程练习题及参考答案
1.输入2个整数,求两数的平方和并输出。 #include
{ int a ,b,s;
printf(\ scanf(\ s=a*a+b*b;
printf(\
}
2. 输入一个圆半径(r)当r>=0时,计算并输出圆的面积和周长,否则,输出提示信息。
#include
#define PI 3.14
main()
{ float r ,s , l;
printf(\ scanf(\
if (r>=0) {s=pi*r*r;
1
计算机程序设计基础(c语言) 习题 编程题
l=2*i*r ;
printf(\
printf(\else
printf(\ }
3、函数y=f(x)可表示为: 2x+1 (x<0) y= 0 (x=0) 2x-1 (x>0)
编程实现输入一个x值,输出y值。 main() {int x,y;
scanf(“%d”,&x); If(x<0)y=2*x+1; If(x>0)y=2*x-1; If(x==0) y=0; printf(“%d”,y);}
4、编写一个程序,从4个整数中找出最小的数,并显示此数。
2
计算机程序设计基础(c语言) 习题 编程题
main( )
{int a,b,c,d,t;
scanf (“%d,%d,%d,%d ”,&a,&b,&c,&d); if (a>b)
{t=a; a=b; b=t;} if (a>c)
{t=a; a=c; c=t;} if (a>d)
{t=a; a=d; d=t;}
printf (“min = %d \\n”,a); }
5.有一函数当x<0时y=1,当x>0时,程,从键盘输入一个x值,输出y值。main() {int x,y; scanf(\if (x<0) y=1; else if(x==0) y=5; else y=3;
printf(\
3
y=3,当x=0时y=5,编
计算机程序设计基础(c语言) 习题 编程题
6.从键盘输入两个数,求出其最大值(要求使用函数完成求最
大值,并在主函数中调用该函数) main()
{float max(float x,float y); float a,b,m;
scanf(\m=max(a,b);
printf(\}
float max(float x,float y) {
float temp; if (x y=temp; } return(x); } 4 计算机程序设计基础(c语言) 习题 编程题 7、从键盘输入你和你朋友的年龄,编成判断谁的年龄最大,并打印最大者的年龄。 #include { int yourAge, hisAge; printf(\ scanf(\&yourAge); /*输入你的年龄yourAge*/ printf(\ scanf(\输入你朋友的年龄hisAge*/ if (yourAge >= hisAge) { printf(\are older! Your age is = %d\\n\yourAge); } if (hisAge > yourAge) { printf(\friend is older! HisAge age is = %d\\n\hisAge); }} 5 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库C语言程序经典例子在线全文阅读。
相关推荐: