第 1 页 共 1 7 页 复习题 C 程序设计编程题 1
输入2 个整数,求两数的平方和并输出
#include void 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 #define PI 3
14 void 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 (x0) 第 2 页 共 1 7 页 编程实现输入一个x 值,输出y 值
#include void main() { int x,y; scanf(“%d”,&x); if(x0) y=2*x-1; else y=0; printf(“%d”,y);} 4、编写一个程序,从 4 个整数中找出最小的数,并显示此数
#include void 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;} pri