输入一个三位数,要求把这个数的百位数与个位数对调,输出对调后的数。
#include <iostream> #include <cstdio> using namespace std; int main(){ int m; cin >> m; int a = m/100; int b = (m/10)%10; int c = m % 10; int n = c*100+b*10+a; cout << "n=" << n << endl; return 0; }
已知某班有男同学x位,女同学y位,x位男生平均分是87分,y位女生的平均分是85分,问全体同学的平均分是多少分?
#include <iostream> #include <cstdio> using namespace std; int main(){ int x,y; cin >> x >> y; cout << float(x*87 + y*85)/(x+y) << endl; return 0; }
歌手大奖赛上6名评委给一位参赛者打分,6个人打分的平均分为9.6分;如果去掉一个最高分,这名参赛者的平局分为9.4分;如果去掉一个最低分,这名参赛者的平均分为9.8分;如果去掉一个最高分和一个最低分,这名参赛者的平均分是多少?
#include <iostream> #include <cstdio> using namespace std; int main(){ float scAll = 6*9.6; float scHigh = 5 * 9.4; float scLow = 5 * 9.8; float high = scAll - scHigh; float low = scAll - scLow; float ans = (scAll - high -low) / 4; printf("%5.2f \n",ans); return 0; }
传说古代的叙拉古国王海伦二世发现的公式,利用三角形的三条边长来求取三角形面积。
即已知△ABC中的三条边长为a,b,c,求△ABC的面积。
[提示:海伦公式s=√p(p-a)(p-b)(b-c),其中p=(a+b+c)/2]
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int main(){ float a,b,c; scanf("%f%f%f",&a,&b,&c); float p = (a+b+c)/2; float s = sqrt(p*(p-a)*(p-b)*(p-c)); printf("%0.3f\n",s); return 0; }
分钱游戏:甲、乙、丙三人共有24元钱,先由甲分给乙、丙两人,所分给的钱数与个人已有数相同;接着由乙分给甲、丙,分法同前;再由丙分钱给甲、乙,分法亦同前。经上述三次分钱之后,每个人的钱数恰好一样多。求原先个人的钱数分别是多少?
#include <iostream> #include <cstdio> using namespace std; int main(){ int a=8,b=8,c=8; a/=2; b/=2; c=a+b+c; a/=2; c/=2; b=a+b+c; b/=2; c/=2; a=a+b+c; printf("a=%-5d,b=%-5d,c=%-5d \n",a,b,c); return 0; }
求一元二次方程x2+3x+2=0的两个实根。
#include <iostream> #include <cstdio> #include <cmath> using namespace std; #define A 1 #define B 3 #define C 2 int main(){ int d = B*B - 4*A*C; float x1,x2; x1 = (-B+sqrt(d))/(2*A); x2 = (-B-sqrt(d))/(2*A); printf("x1=%-8.3f,x2=%-8.3f \n",x1,x2); return 0; }
#include <iostream> using namespace std; int main() { double a,b; cin >> a >> b ; int c = (int)(a / b); printf("%g", a - b*c); return 0; }
#include <iostream> using namespace std; int main() { double pi = 3.14; double r; cin >> r ; printf("%.2f", 4 * pi * r*r*r/3); return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n ; int h = n /100; printf("%d%d%d", (n - h * 100 )%10, (n - h * 100)/10, n/100 ); return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { double pi = 3.14159; double h,r; cin >> h >> r ; double v = pi * r * r * h / 1000; printf("%g", ceil(20/v) ); return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { double n,x,y; cin >> n >> x >> y ; printf("%g", n-ceil(y/x) ); return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { double xa,ya; double xb,yb; cin >> xa >> ya; cin >> xb >> yb; printf("%.3f", sqrt(pow(xa-xb,2)+pow(ya-yb,2)) ); return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { double x1,y1,x2,y2,x3,y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double l1 = sqrt(pow(x1-x2,2)+pow(y1-y2,2)); double l2 = sqrt(pow(x2-x3,2)+pow(y2-y3,2)); double l3 = sqrt(pow(x1-x3,2)+pow(y1-y3,2)); double p = (l1 + l2 + l3) / 2; printf("%.2f", sqrt(p*(p-l1)*(p-l2)*(p-l3))); return 0; }
#include <iostream> using namespace std; int main() { int a1,a2,n; cin >> a1 >> a2 >> n; printf("%d", a1 + (n-1) * (a2-a1)); return 0; }
#include <iostream> using namespace std; int main() { long a,b; cin >> a >> b; cout << a * b << endl; return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { int n; cin >> n; int p = pow(2,n); cout << p << endl; return 0; }