习题1-1 平均数(average)
<span style="font-size:24px;"><strong><span style="font-size:18px;"><span style="font-size:18px;">#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
float n;
scanf("%d%d%d", &a, &b, &c);
n = (a + b + c) / 3.0;
printf("%.3f\n", n);
return 0;
}</span></span></strong></span>
习题1-2 温度(temperature)
<span style="font-size:24px;"><strong><strong><span style="font-size:18px;"><span style="font-size:18px;">#include <stdio.h>
int main()
{
float f, c;
scanf("%f\n", &f);
c = 5 * (f - 32) / 9;
printf("%.3lf\n", c);
return 0;
}
</span></span></strong></strong></span>
习题1-3 连续和(sum)
<strong><span style="font-size:24px;"><span style="font-size:18px;"><strong>#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d\n", &n);
printf("%d\n", n * (n + 1) / 2);
return 0;
}</strong></span></span></strong>
习题1-4 正弦和余弦(sincos)
<span style="font-size:24px;"><strong><strong><span style="font-size:18px;">#include <stdio.h>
#include <math.h>
int main()
{
int n;
const double pi = 4.0 * atan(1.0);
scanf("%d\n", &n);
printf("%lf\n%lf\n", sin((pi * n) / 180), cos((pi * n) / 180));
return 0;
}</span></strong></strong></span>
习题1-5 距离(distance)
<strong><span style="font-size:24px;"><strong><span style="font-size:18px;">#include <stdio.h>
#include <math.h>
int main()
{
float x1, y1, x2, y2;
scanf("%f\n%f\n%f\n%f", &x1, &y1, &x2, &y2);
printf("%lf\n", sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
return 0;
}</span></strong></span></strong>
习题1-6 偶数(odd)
<strong><span style="font-size:24px;"><span style="font-size:18px;"><strong>#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d\n", &n);
if(n % 2 == 0)
{
printf("yes\n");
}
else
{
printf("no\n");
}
return 0;
}</strong></span></span></strong>
习题1-7 打折(discount)
<span style="font-size:24px;"><strong><span style="font-size:18px;"><strong>#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d\n", &n);
if(n <= 3)
{
printf("%d\n", n * 95);
}
else
{
printf("%.2f\n", n * 95 * 0.85);
}
return 0;
}</strong></span></strong></span>
习题1-8 绝对值(abs)
<strong><span style="font-size:24px;"><strong><span style="font-size:18px;">#include <stdio.h>
#include <stdlib.h>
int main()
{
double n;
scanf("%lf\n", &n);
printf("%.2lf\n", fabs(n));
return 0;
}</span></strong></span></strong>
习题1-9 三角形(triangle)
<strong><span style="font-size:24px;"><span style="font-size:18px;"><strong>#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if((a==b) && (b==c))
{
printf("no");
}
else if((a*a+b*b == c*c) || (a*a+c*c == b*b) || (b*b+c*c == a*a))
{
printf("yes");
}
else
{
printf("no");
}
return 0;
}</strong></span></span></strong>
习题1-10 年份(year)
<strong><span style="font-size:24px;"><span style="font-size:18px;"><strong>#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d\n", &n);
if(n % 400 == 0)
{
printf("yes");
}
else if(n % 4 == 0)
{
if(n % 100 != 0)
{
printf("yes");
}
else
{
printf("no");
}
}
else
{
printf("no");
}
return 0;
}</strong></span></span></strong>