基本编程题.docVIP

  1. 1、本文档共17页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
基本编程题.doc

北京石油化工学院 12级复习题 C程序设计编程题 1.输入2个整数,求两数的平方和并输出。 #include stdio.h 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),计算并输出圆的面积和周长#include stdio.h #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) y= 0 (x=0) 2x-1 (x0) 编程实现输入一个x值,输出y值。 main() { int x,y; scanf(“%d”,x); if(x0) y=2*x+1; else if(x0) y=2*x-1; else y=0; printf(“%d”,y);} 4、编写一个程序,从4个整数中找出最小的数,并显示此数。 #include stdio.h void main( ) {int a,b,c,d,t; scanf (“%d,%d,%d,%d ”,a,b,c,d); if (ab) {t=a; a=b; b=t;} if (ac) {t=a; a=c; c=t;} if (ad) {t=a; a=d; d=t;} printf (“min = %d \n”,a); } 5.有一函数当x0时y=1,当x0时,y=3,当x=0时y=5,编程,从键盘输入一个x值,输出y值。 #include stdio.h void main() {int x,y; scanf(%d,x); if (x0) y=1; else if(x==0) y=5; else y=3; printf(x=%d,y=%d\n,x,y);} 6.从键盘输入两个数,求出其最大值(要求使用函数完成求最大值,并在主函数中调用该函数) #include stdio.h 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 (xy) {temp=x; x=y; y=temp; } return(x); } 7、#include stdio.h void main() { int yourAge, hisAge; printf(Please enter your age:); scanf(%d, yourAge); /*输入你的年龄yourAge*/ printf(Please enter your friends age:); scanf(%d, hisAge); /*输入你朋友的年龄hisAge*/ if (yourAge = hisAge)  { printf(You are older! Your age is = %d\n, yourAge);  } if (hisAge yourAge)  { printf(Your friend is older! HisAge age is = %d\n, hisAge);  }} right”,否则显示“error” #include “stdio.h” void main( ) {int a,b,c; printf(“please input a and b\n”); scanf (%d,%d”,a,b); printf(“please input the answer for a+b\n”); scanf (%d”

您可能关注的文档

文档评论(0)

jackzjh + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档