电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C语言基本编程题

C语言基本编程题_第1页
1/18
C语言基本编程题_第2页
2/18
C语言基本编程题_第3页
3/18
复习题 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 (x<0) y= 0 (x=0) 2x-1 (x>0) 编程实现输入一个 x 值,输出 y 值。 #include void main(){ int x,y;scanf(“%d”,&x);if(x<0) y=2*x+1;else if(x>0) 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;} printf (“min = %d \n”,a);}5.有一函数当 x<0 时 y=1,当 x>0 时,y=3,当 x=0 时 y=5,编程,从键盘输入一个 x 值,输出 y 值。#include void 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.从键盘输入两个数,求出其最大值(要求使用函数完成求最大值,并在主函数中调用该函数) #include float max(float x,float y);void main(){ 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 (xvoid main(){ int yourAge, hisAge;printf("Please enter your age:");scanf("%d", &yourAge); /*输入你的年龄 yourAge*/printf("Please enter your friend's age:");scanf("%d", &hisAge); /*输入你朋友的年龄 hisAge*/if (yourAge >= hisAge) {printf("You are...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

C语言基本编程题

您可能关注的文档

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部