山东大学23强基班计算机导论第二次习题答案
T1
#include <stdio.h>
int main() {
int fahr = 150;
int celsius = 5 * (fahr - 32) / 9;
printf("fahr = %d, celsius = %d", fahr, celsius);
}
T2
#include <stdio.h>
int main() {
float heigth = 100;
float growth = 10;
float seconds = 3;
float result = 0;
result = 10.0 * 3.0 * 3.0 / 2.0;
printf("height = %.2f", result);
}
T3
#include <stdio.h>
int main() {
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
int sum = a + b + c + d;
float avg = sum / 4.0;
printf("Sum = %d; Average = %.1f",sum,avg);
}
T4
#include <stdio.h>
int main()
{
printf("%d %d %d %d %d %d %d",sizeof(double),sizeof(long double),sizeof(long long),sizeof(3.14F),sizeof(3.14),sizeof(521),sizeof(521LL));
}
T5
#include <stdio.h>
int main()
{
int sum = 100 * 100;
int x,y;
scanf("%d%d",&x,&y);
sum -= x * y;
sum -= 2 * (100 - x) * y;
sum -= (100 - x) * (100 - y);
printf("%d",sum/2);
}
T6
#include <stdio.h>
#define out(a,b,c,o) printf("%d %c %d = %d\n",a,c,b,o)
int main()
{
int A,B;
scanf("%d%d",&A,&B);
out(A,B,'+',A+B);
out(A,B,'-',A-B);
out(A,B,'*',A * B);
out(A,B,'/',A/B);
out(A,B,'%',A%B);
}
T7
#include <stdio.h>
int main()
{
float a,d;
int b;
char c;
scanf("%f %d %c %f",&a,&b,&c,&d);
printf("%c %d %.2f %.2f",c,b,a,d);
}
T8
#include <stdio.h>
#include <math.h>
int main()
{
double cm;
scanf("%lf",&cm);
double foot = cm / 100.0 / 0.3048 * 12;
printf("%d %d",(int)foot / 12,(int)foot % 12);
}
T9
#include <stdio.h>
int main()
{
int a = 8, b = 9,c = 10;
int r = 0;
int avg = 0;
avg = a / 3;
a = avg;
b += avg;
c += avg;
avg = b / 3;
a+= avg;
b = avg;
c += avg;
avg = c / 3;
a+= avg;
b+= avg;
c=avg ;
printf("%d %d %d",a,b,c);
}
T10
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int t= n;
int sum = 1;
while(n--)
sum*=2;
printf("2^%d = %d",t,sum);
}