1 / 32

# 程序设计基础作业集答案高涛.docx

0 / 32

1．硬件系统、软件系统
2．中央处理器、存储器、输入设备、输出设备
3．系统软件、应用软件
units=a-hundreds*100-tens*10;
b=100*units+tens*10+hundreds;
printf("after change,the number is:%d\n",b);
}
2．解： #include <stdio.h>
void main()
{
int a ,b,c;
scanf("%d%d%d",a,b,c);
if(a>b) if(b>c) printf("mid=%d\n",b);
else if(a>c) printf("mid=%d\n",c);
else printf("mid=%d\n",a);
else if(a>c) printf("mid=%d\n",a);
else if(b>c) printf("mid=%d\n",c);
else printf("mid=%d\n",b);
}

5 / 32

3．解：#include <stdio.h>
#include <math.h>
void main()
{
double a,b,c; /*方程系数*/
double disc; /*判别式*/
double re,im; /*方程实部虚部*/
printf("Enter a,b,c:");
scanf("%lf%lf%lf",&a,&b,&c);
if(a==0.0)
if(b==0.0)
printf("The equation has not soluble!\n");
else
printf("Single root is %f\n",-c/b);
else if(c==0.0)
printf("Two roots:x1=%lf\t x2=%lf\n",-b/a,0);
else
{
disc=b*b-4*a*c;
re=-b/(2*a);
im=sqrt(fabs(disc))/(2*a);
if(disc>=0.0)

6 / 32

printf("Two roots:x1=%f\t x2=%f",re+im,re-im);
else
printf("Two complex roots:x1=%f+i*%f\t x2=%f-i*%f\n",re,im,re,im);
}
}
4．解：#include <stdio.h>
#include <math.h>
void main()
{
int i,j,result;
printf("\n");
for(i=1;i<10;i++)
{
for(j=1;j<10;j++)
{
result=i*j;
printf("%d*%d=%-3d",i,j,result);
}
printf("\n");
}
}

7 / 32

5．答： #include <stdio.h>
void main()
{
float a,b;
char optor;
printf("Please input the value of a,b:");
scanf("%f%f",&a,&b);

printf("Enter operator:");
getchar();
scanf("%c",&optor);
switch(optor)
{
case