计算机程序设计基础(C 语言)编程练习题及参考答案1.输入 2 个整数,求两数的平方和并输出。 #include main(){ intt a ,b,s; printf(”please input a,b:\n"); scanf("%d%d",&a,&b); s=a*a+b*b; printf("the result is %d\n”,s); } 2。 输入一个圆半径(r)当 r>=0 时,计算并输出圆的面积和周长,否则,输出提示信息.#include 〈stdio.h> #define PI 3。14 〈stdio。h〉main(){ float r ,s , l; printf("please input r:\n”); scanf(”%f”,&r);if (r〉=0) {s=pi*r*r; l=2*i*r ; printf("the area is %f\n”,s);printf("the circumference is %f\n”,l);}else printf(”input error!\n"); } 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 个整数中找出最小的数,并显示此数。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 时,y=3,当 x=0 时 y=5,编程,从键盘输入一个 x 值,输出 y 值.main(){int x,y;scanf("%d",&x);if (x<0) y=1;else if(x==0) y=5;else y=3;printf("x=%d,y=%d\n”,x,y);}6.从键盘输入两个数,求出其最大值(要求使用函数完成求最大值,并在主函数中调用该函数)main(){float max(float x,float y); float a,b,m;scanf(”%f,%f",&a,&b);m=max(a,b);printf("Max is %f\n",m);}float max(float x,float y){float temp;if (xmain(){int yourAge, hisAge;printf(”Please enter your age:");scanf("%d", &yourAge); /*输入你的年龄 yourAge*/printf(”Please enter your friend's age:”);scanf("%d", &hisAge); /*输入你朋友的...