y) {a=x; x=y;y=a;}if(x>z) { a=x; x=z; z=a;}if(y>z) {a=y; y=z; z=a;}printf("%d,%d,%d\n",x" />

C语言上机练习题及答案

  • 格式:doc
  • 大小:61.50 KB
  • 文档页数:10

下载文档原格式

  / 10
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1输入三个整数x,y,z,把这三个数由小到大输出。

# include

void main()

{

int x,y,z,a;

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

if(x>y) {a=x; x=y;y=a;

}

if(x>z) { a=x; x=z; z=a;

}

if(y>z) {a=y; y=z; z=a;

}

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

}

2输入圆的半径,输出圆的周长和面积。

# include

# define PI 3.1415926

# define S ==PI*r*r

# define V (4.0/3)*PI*r*r*r

void main()

{

double r;

printf("please input r:");

scanf("%lf",&r);

printf("area is %.4lf\n",S);

printf("volume is %.4lf\n",V);

}

输入正方形的边长,输出正方形的周长和面积。

# include

void main()

{

float c,zc,mj;

printf("输入你的正方形");

scanf("%f\n",&c);

zc=4*c;

mj=c*c;

printf("周长%f,面积%f,边长%f",zc,mj,c);

}

3用格式输入函数输入3个字符,并用输出函数反向输出3个字符和他们的ASCII 码。

# include

int main()

{char-ch1,ch2,ch3;

printf("please input three characters:\n");

scanf("%C%C%c",&ch1,&ch2,&ch3);

printf("%c\n%d\n",ch3,ch3);

printf("%c\n%d\n",ch2,ch2);

printf("%c\n%d\n",ch1,ch1);

}

输入一个摄氏温度,要求输出华氏温度。公式为f=9/5*c+32。# include

void main()

{

float C,F;

scanf("%f",&F);

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

printf("%8.2f",C);

}

4。比较两个数大小的题

#include

void main()

{ int a,b;

scanf("%d,%d",&a,&b);

if(a>b) printf("%d\n",a);

else printf("%d\n",b);

}

第二题:此题作废(千万不要用)

#include

voidmain()

{ char a,b,c;

scanf("%c,%c,%c",&a,&b,&c);

while((a<97||a>122)||(b<97||b>122)||(c<97||c>122));

{

printf("您输入非三个小写字母,请重新输入:\n");

scanf("%c,%c,%c",&a,&b,&c);

}

printf("%c,%c,%c\n",a-32,b-32,c-32);

}

5输入任意10个数,求他们的平均值。

# include

void main()

{

Printf( "请输入10个整数:" );

int a[10], k = 0, sum = 0;

for (int i = 0; i < 10; ++i) ;

{

i>a[i];

if 10>=a[i] >0 ++k;

sum = sum+a[i];

}

float ave=sum / 10 .0

printf( "平均值为:%f\n",ave);

}

6实现从键盘输入两个整数,按从小到大次序输出这两个数。

# include

void main()

{

int a, b, tem;

printf("input two numbers:\n");

scanf("%d,%d",&a,&b );

if(a>b)

{

tem=a;a=b;b=tem;

}

printf ("%d,%d",a,b);

7从键盘输入三个整数,输出最大的那个数。

#include

void main()

{

int a,b,c,max;

printf("请输入三个整数:\n");

scanf("%d%d%d",&a,&b,&c);

max=a>b?a:b;

max=max>c?max:c;

printf(“max=%d\n”,max);

}

}

8输入任意一个三位数,将其各位数字反序输出(例如输入123,输出321)。# include

void main()

{

int x,y,z,n;

printf("please input an integer less than 1000\n");

scanf("%d",&n);

x=n/100; n=n-100*x; y=n/10;z=n-10*y;

if (x>0)printf("%d%d%d\n",z,y,x);

else if(y>0) printf("%d%d\n",z,y);

else printf("%d\n",z);