c语言程序答案_第1页
c语言程序答案_第2页
c语言程序答案_第3页
c语言程序答案_第4页
c语言程序答案_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#inelude mai n()const double pi 二 3.14159;double r;double circum;double area;printf(Input r:);scanf(%lf, &r);circum = 2 * pi * r;area = pi * r * r;printf(printf WITHOUT width or precision specifications:n);printf(circumference 二 %f, area 二 fn, circum, area);printf(printf WITH width and precision spe

2、cifications:n);printf(circumference 二 %7.2f, area 二 %7.2fn, circum, area);使用const常量定义圆周率pi (取值为3.14159),编程从键盘输入圆的半径r,计算并输 出圆的周长和面积。输出的数据保留两位小数点。*输入格式要求:%lf提示信息:Inp ut r: *输出格式要求: printf WITHOUT width or precision specifications:n circumfer ence = %f, area = %fn printf WITH width and precision specif

3、ications:n circumfere nce = %7.2f, area = %7.2fn 程序运行示例如下: Input r:5.3 printf WITHOUT width or precision specifications: circumference = 33.300854, area = 88.247263 printf WITH wid th and precision specifications: circumference = 33.30, area = 88.25 #includemain()int a,b,c;double p,q,x1,x2;printf(Pl

4、ease enter the coefficients a,b,c:);scanf(%f,%f,%f,&a,&b,&c);p=-b/a;q=(bA2-4ac)A0.5/(2a);x1=p-q;x2=p+q;#includeMain()int a,b,c;double p,q,x1,x2;printf(Please enter the coefficients a,b,c:);scanf(%f,%f,%f,&a,&b,&c);p=-b/a;q=(bA2-4ac)A0.5/(2a);x1=p-q;x2=p+q;计算输入的两个整数的和。*输入格式要求:%d提示信息:请输入第一个整数:请 输入第二个整

5、数: *输出格式要求: %d + %d = %dn 程序运行示例如下: 请输入第一 个整数:34请输入第二个整数:56 34 + 56 = 90#inelude int main()int n1; 定义第一个整型变量n1int n2; 定义第一个整型变量n2printf(请输入第一个整数:);务必养成好习惯:任何输入前先给出输入提示!scanf(%d, &n 1);接收第一个整数 n1printf(请输入第二个整数:);务必养成好习惯:任何输入前先给出输入提示!scanf(%d, &n2);接收第二个整数 n2printf(%d + %d = %dn, n1, n2, n1 + n2);/*每

6、一个格式控制符%d控制后面的一项,第一个%d控制n1,第二个%d控制n2第三个%d控制n1+n2,%d用于控制输出项以十进制有符号整数的形式输出,其它的格式控制字符串中的字符,如+,二等原样输出,n为换行符*/return 0;学校有近千名学生(大于等于900,小于1000),在操场上排队,5 人一行余 2 人,7 人一 行余3人,3人一行余1人,编写一个程序求该校的学生人数。*输出格式要求:there a re %d students in the groundn#inelude int main()int n;for (n 二 900; n 1000; n + +)if (n % 5 =

7、2 & n % 7 = 3& n % 3 = 1)printf(there are %d students in the groundn, n);假设对折一张厚度为0.1mm的纸,请问要对折多少次才能使纸的厚度从地球到达月球(假 设地球到月球的距离为30万km)? *输出格式要求:%d#in elude #in elude int ma in()prin tf(%d, (in t)eeil(log10(3.0) + 12) / log10(2.0);retu rn 0;请使用short int型的变量计算两个7位十进制整数的和,要求使用尽可能少的变量。 *输入格式要求:a 二 3hd%4hd,

8、 b 二 3hd%4hd*输出格式要求:a + b = %d程序运行示例如下:a 二 1234567,b 二 7654321输出a + b 二 8888888#in elude int ma in()sho rt int d, m, c, n;sea nf(a 二 %3hd%4hd, b 二 %3hd%4hd, &d, &m, &c, &n);prin tf(a + b 二 %d, (d + c) * 10000 + m + n);retu rn 0;华氏和摄氏温度的转换公式为:C 二 5/9 x (F-32)其中,C表示摄氏温度,F表示华氏温度。要求:华氏0F300F,每隔20F输出一个华氏

9、温度对应的摄氏温度值。*输入提示信息要求:无*输入数据格式要求:无*输出数据格式要求:%4.0f%10.1fn(第一个浮点数为华氏温度,第二个浮点数为摄氏温度)#in elude int ma in()int uppe r, step;float f 二 0, c;uppe r 二 300;step 二 20;while (f = upp er)c 二 5.0 / 9 * (f - 32);prin tf(%4.0f%10.1fn, f, c);f 二 f + step;retu rn 0;编程输出以下形式的乘法九九表: 1*1= 1 2*1= 2 2*2= 4 3*1= 3 3*2= 6 3

10、*3= 9 4*1= 4 4*2= 8 4*3=12 4*4=16 5*1= 5 5*2=10 5*3=15 5*4=20 5*5=25 6*1= 6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 7*1= 7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=498*1= 8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 9*1= 9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 *输出格式要求:1d*%1d二2d #ine

11、lude mai n()int i,j;for (i = 1;i=9;i + +)for (j = 1;j = i;j + +)printf(%d*%d=%2d ,i,j,i*j);prin tf(n);小明今年12岁,他母亲比他大24岁。编写一个程序计算小明的母亲在几年后比小明的年 龄大一倍,那时他们两人的年龄各是多少?*输出格式要求: year=%dn mingAge=%dn motherAge=%dn 程序运行示例如下:year=12mingAge=24 motherAge=48 #include int main()int mingAge, motherAge, year;mingAg

12、e = 12;motherAge = mingAge + 24;year = 1;while (motherAge + year) != 2 * (mingAge + year)year = year + 1;printf(year=%dn, year);printf(mingAge=%dn, mingAge + year); printf(motherAge=%dn, motherAge + year); return 0;用二维数组作为函数的参数,实现并输出矩阵的转置和转置后矩阵副对角线元素之和。按如 下函数原型编程计算。其中n的值由用户从键盘输入。使用ProduceMatrix函数生成n

13、阶方 阵,以start值作为矩阵的第一个元素a11,每行下一个元素比该行上一个元素大1,每行 第元素比上一行最后元素大1.例如n=3,start=3时ProduceMatrix生成的矩阵为: TOC o 1-5 h z 34567891011已知m和n的取值范围为1,30.函数原型为void Transpose(int aN,int n);void ProduceMatrix(int aN,int n,int start);void PrintMatrix(int atN, int n);int SumCounterDiagonal(int aN,int n); 求矩阵副对角线元素之和输入提示

14、信息: Input n:n Input %d*%d matrixs start element:n 输入格式:%d输出提示信息和格式:The transposed matrix is:nThe sum of the matrix-counter-diagonal is:%dn输出格式(输完矩阵的一行要换行):%4d注意除了 PrintMatrix外的输入输出均在main函数里面#i nclude#define N 30void Transpose(int aN, int n);void ProduceMatrix(int aN, int n, int start);void PrintMatr

15、ix(int aN, int n);int SumCounterDiagonal(int aN, int n);int main()int n , sum 二 0, start 二 0;int aNN二0;/1printf(Input n:n);scanf(%d, &n);printf(Input %d*%d matrixs start element:n, n, n);sca nf(%d, &sta rt);/1ProduceMatrix(a, n, start);Transpose(a, n);/1printf(The transposed matrix is:n);PrintMatrix

16、(a, n);/1sum 二 SumCounterDiagonal(a, n);printf(The sum of the matrix-counter-diagonal is:%dn, sum);return 0;void ProduceMatrix(int aN, int n, int start)int i, j;a00二 sta rt;for (i = 0; i n; i + +)/1for (j = 0; j 0 & j = 0)aij二 ai - 1n - 1 + 1;/1 elseaij = aij - 1 + 1;/1void Transpose(int aN, int n)inti,j,temp;for(i 二0; i n; i + +)for(j = i;j n; j + +)temp=aij;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论