1031:反向输出一个三位数
【题目描述】
将一个三位数反向输出,例如输入358,反向输出853。
【输入】
一个三位数n。
【输出】
反向输出n。
【输入样例】
100
【输出样例】
001
#include <stdio.h>
int main() {
int n, reversedNumber;
int hundreds, tens, ones;
scanf("%d", &n);
hundreds = n / 100;
tens = (n / 10) % 10;
ones = n % 10;
reversedNumber = ones * 100 + tens * 10 + hundreds;
printf("%03d\n", reversedNumber);
return 0;
}
1032:大象喝水
【题目描述】
一只大象口渴了,要喝20升水才能解渴,但现在只有一个深h厘米,底面半径为r厘米的小圆桶(h和r都是整数)。问大象至少要喝多少桶水才会解渴。
【输入】
输入有一行:包行两个整数,以一个空格分开,分别表示小圆桶的深h和底面半径r,单位都是厘米。
【输出】
输出一行,包含一个整数,表示大象至少要喝水的桶数。
【输入样例】
23 11
【输出样例】
3
#include <stdio.h>
int main()
{
int h,r,V,count=0;
float PI = 3.14;
scanf("%d%d", &h,&r);
V = PI * r * r * h;
count = 20000 / V;
if (20000 % V != 0)
{
count += 1;
}
printf("%d",count);
return 0;
}
1033:计算线段长度
【题目描述】
已知线段的两个端点的坐标A(Xa,Ya),B(Xb,Yb),求线段AB的长度,保留到小数点后3位。
【输入】
第一行是两个实数Xa,Ya,即A的坐标。
第二行是两个实数Xb,Yb,即B的坐标。
输入中所有实数的绝对值均不超过10000。
【输出】
一个实数,即线段AB的长度,保留到小数点后3位。
【输入样例】
1 1
2 2
【输出样例】
1.414
#include <stdio.h>
#include <math.h>
int main()
{
double a, b,c,d;
double l;
scanf("%lf%lf", &a, &b);
scanf("%lf%lf", &c, &d);
l = sqrt(pow(d - b, 2) + pow(c - a, 2));
printf("%.3lf",l);
return 0;
}
1034:计算三角形面积
【题目描述】
平面上有一个三角形,它的三个顶点坐标分别为(x1,y1),(x2,y2),(x3,y3),那么请问这个三角形的面积是多少,精确到小数点后两位。
【输入】
输入仅一行,包括6个双精度浮点数,分别对应x1,y1,x2,y2,x3,y3。
【输出】
输出也是一行,输出三角形的面积,精确到小数点后两位。
【输入样例】
0 0 4 0 0 3
【输出样例】
6.00
#include <stdio.h>
#include <math.h>
int main()
{
double x1, x2, x3, y1, y2, y3,s;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
s = fabs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0;
printf("%.2lf",s);
return 0;
}
1035:等差数列末项计算
【题目描述】
给出一个等差数列的前两项a1,a2,求第n项是多少。
【输入】
一行,包含三个整数a1,a2,n。−100≤a1,a2≤100,0<n≤1000。
【输出】
一个整数,即第n项的值。
【输入样例】
1 4 100
【输出样例】
298
#include <stdio.h>
#include <math.h>
int main()
{
int a1, a2, n,c;
scanf("%d%d%d", &a1, &a2, &n);
c = a2 - a1;
for (int i = 3; i <= n; i++)
{
a2 += c;
}
printf("%d", a2);
}