C语言实训题16章.docx

上传人:b****6 文档编号:3064237 上传时间:2022-11-17 格式:DOCX 页数:12 大小:21.73KB
下载 相关 举报
C语言实训题16章.docx_第1页
第1页 / 共12页
C语言实训题16章.docx_第2页
第2页 / 共12页
C语言实训题16章.docx_第3页
第3页 / 共12页
C语言实训题16章.docx_第4页
第4页 / 共12页
C语言实训题16章.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

C语言实训题16章.docx

《C语言实训题16章.docx》由会员分享,可在线阅读,更多相关《C语言实训题16章.docx(12页珍藏版)》请在冰豆网上搜索。

C语言实训题16章.docx

C语言实训题16章

1.3.1:

请参照本章例题,编写一个C程序,从键盘上输入圆的半径,求园的周长和以此半径所组成的球的体积。

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

{floatr,c,v,pi=3.14;

printf("r:

");scanf("%f",&r);

c=2*pi*r;

v=4.0/3*pi*r*r*r;

printf("c=%f\n",c);

printf("v=%f\n",v);

getch();

}

132:

编写一个C程序,输入45,21,60三个数字,输出其中的最大者。

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

intmax(intx,inty,intz)

{

intm;

m=x>y?

x:

y;

return(m>z?

m:

z);}

main()

{intx,y,z;

printf("x:

");scanf("%d",&x);

printf("y:

");

scanf("%d",&y);

printf("z:

");

scanf("%d",&z);

printf("max=%d\n",max(x,y,z));

getch();

}

2.6.1.1:

观察分析程序的结果,并与人工计算结果进行比较。

/*HELLO.C--Hello,world*/

#include"stdio.h"

voidmain()

{charc1,c2;

c1=97;c2=98;

printf("%c%c\n",c1,c2);

printf("%d%d\n",c1,c2);

c1=c1-('a'-'A');

printf("%c%c\n",c1,c2);

getch();

}

2.6.2:

参照下列求圆面积与园周长的程序,编写已知圆半径、圆柱高,求圆周长和圆柱体积的程序。

/*HELLO.C--Hello,world*/

#include"stdio.h"

#definepi3.1415926

voidmain()

{floatr,h,v,len;

printf("r:

");scanf("%f",&r);

printf("h:

");

scanf("%f",&h);

len=2*pi*r;

v=pi*r*r*h;

printf("\nv=%f,length=%f",v,len);

getch();

}

3.7.1:

编写程序,使得该程序运行后显示下面一首诗:

lifeisdearindeed,

loveispricelesstoo,butforfreedom'ssake,Imaypartwiththetwo.

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

{

printf("lifeisdearindeed,\nloveispricelesstoo,\nbutforfreedom'ssake,\nImaypartwiththetwo.");

getch();

}

3.7.2:

用格式控制符打印下面图形:

*****

*******

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

getch();

}

3.7.3:

编写程序,输入一个华氏温度(F),按下面的公式计算并输出对应的摄氏温度(C))计算公式为C=5(F-32)/9。

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"main()

{floatF,C;printf("F:

");scanf("%f",&F);

C=5*(F-32)/9;

printf("C=%f\n",C);getch();

}

4.5.1:

编写程序,输入一个日期,判断该日期是这一年的第几天

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

{intday,month,year,sum,leap;

printf("\npleaseinputyear,month,day\n");

scanf("%d,%d,%d",&year,&month,&day);

switch(month)

{

case1:

sum=0;break;

case2:

sum=31;break;

case3:

sum=59;break;

case4:

sum=90;break;

case5:

sum=120;break;

case6:

sum=151;break;

case7:

sum=181;break;

case8:

sum=212;break;

case9:

sum=243;break;

case10:

sum=273;break;

case11:

sum=304;break;

case12:

sum=334;break;

default:

printf("dataerror");

break;

}

sum=sum+day;

if(year%400==0||(year%4==0&&year%100!

=0))

leap=1;

else

leap=0;

if(leap==1&&month>2)

sum++;

printf("itisthe%dthday\n",sum);

getch();

}

4.5.2:

编写程序,对于输入的三个数,将他们降序输出

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"main(){floatx,y,z,temp;

printf("Pleaseinputthreenumber:

\n");

scanf("%f,%f,%f",&x,&y,&z);

if(x>y)

{temp=x;

x=y;

y=temp;

}

if(x>z)

{temp=x;

x=z;

z=temp;

}

if(y>z)

{temp=y;

y=z;

z=temp;

}

printf("thesequenceis:

%3.1f,%3.1f,%3.1f\n",z,y,x);

getch();

}

4.5.4:

某大型电器公司在国庆节期间推出以下促销优惠活动:

当天所购商品价值在20000元以上(包括20000元)的顾客,将享受7.5折优惠;当天所购商品价值在15000元以上(包括15000元)的顾客,将享受8折优惠;当天所购商品价值在10000元以上(包括10000元)的顾客,将享受8.5折优惠;当天所购商品价值在5000元以上(包括5000元)的顾客,将享受9折优惠;其他顾客享受9.5折优惠。

编写实现该优惠活动的程序。

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

{

floatx;

floaty;

printf("pleaseinputax:

\n");

scanf("%f",&x);

if(x>=20000)

{y=x*0.75;}

elseif(x>=15000)

{y=x*0.8;}

elseif(x>=10000)

{y=x*0.85;}

elseif(x>=5000){y=x*0.9;}else{y=x*0.95;}printf("%f\n",y);getch();

}

4.5.5:

写出实现以下函数的对应程序,要求:

输入x,计算并输出函数y的值(保留两位小数)。

X+10,(x<0)

Y=20,(x=0)

30x,(x>0)

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

{

floatx;

floaty;

printf("pleaseinputax:

\n");

scanf("%f",&x);

if(x>0){y=x*30;}

elseif(x<0)

{y=x+10;}

else

{y=20;}

printf("%f\n",y);

getch();

}

4.5.10:

输入一个4位正整数,求出对应位的数字并输出,最后将千位和十位互换,百位和个位互换并输出(例:

输入1256,最后输出5612),其他输入提示

错误。

#include"stdio.h"

voidmain()

{

intx,y,a,b,c,d;

printf("pleaseinputonenumber:

");

scanf("%i",&x);

if(x>=1000&&x<10000)

{

a=x%10;printf("%d\n",a);b=(x/10)%10;printf("%d\n",b);c=(x/100)%10;printf("%d\n",c);

d=(x/1000)%10;printf("%d\n",d);y=b*1000+a*100+d*10+c;printf("%d\n",y);

}

else

{

printf("sorryERROR");

}

getch();

}

5.5.3.2:

编一程序输出如下图形:

1

121

12321

1234321

123454321

12345654321

/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"

main()

{inti,j;

for(i=1;i<=6;i++)

{for(j=1;j<=6-i;j++)

printf("");

for(j=1;j<=i;j++)

printf("%d",j);

for(j=i-1;j>=1;j--)

printf("%d",j);

printf("\n");

}

getch();

从第

5.6.3:

设计程序输出Fibonacci数列的前50个数,其开始两个数是1、1三个数开始,每个数等于前两个数之和。

例如,1、1、2、3、5、8、13、/*HELLO.C--Hello,world*/

#include"stdio.h"

#include"conio.h"intmain()

{

longx[16]={0,1};

inti;

for(i=2;i<16;i++)x[i]=x[i-1]+x[i-2];for(i=1;i<16;i++)printf("F%d=%d\n",i,x[i]);

getch();

}

5.6.7:

用循环程序输出以下图案。

*

*****

*******

*****

/*HELLO.C--Hello,world*/

#inc

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1