1.3.1
描述
在大部分的在線題庫中,都會將A+B問題作為第一題,以幫助新手熟悉平台的使用方法。
A+B問題的題目描述如下:給定兩個整數A和B,輸出A+B的值。保證A、B及結果均在整型范圍內。
現在請你解決這一問題。
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
c=a+b;
cout<<c;
return 0;
}
1.3.2
描述
給定3個整數a、b、c,計算表達式(a+b)*c的值。
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c;
d=(a+b)*c;
cout<<d;
return 0;
}
1.3.3
描述
給定3個整數a、b、c,計算表達式(a+b)/c的值,/是整除運算。
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c;
d=(a+b)/c;
cout<<d;
return 0;
}
1.3.4
描述
給定被除數和除數,求整數商及余數。
此題中請使用默認的整除和取余運算,無需對結果進行任何特殊處理。看看程序運行結果與數學上的定義有什么不同?
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b;
c=a/b;
d=a%b;
cout<<c<<" "<<d;
return 0;
}
1.3.5
描述
兩個整數a和b分別作為分子和分母,既分數 a/b ,求它的浮點數值(雙精度浮點數,保留小數點后9位)
#include<cstdio>
using namespace std;
int main()
{
double a,b,c;
scanf("%lf%lf",&a,&b);
c=a/b;
printf("%.9lf",c);
return 0;
}
1.3.6
描述
甲流並不可怕,在中國,它的死亡率並不是很高。請根據截止2009年12月22日各省報告的甲流確診數和死亡數,計算甲流在各省的死亡率
#include<cstdio>
using namespace std;
int main()
{
double a,b,c;
scanf("%lf%lf",&a,&b);
c=100*b/a;
printf("%.3lf%%",c);
return 0;
}
1.3.7
描述
對於多項式f(x) = ax^3 + bx^2 + cx + d 和給定的a, b, c, d, x,計算f(x)的值。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double x,a,b,c,d,s;
cin>>x>>a>>b>>c>>d;
s=a*x*x*x+b*x*x+c*x+d;
printf("%.7lf",s);
return 0;
}
1.3.8
描述
利用公式 C = 5 * (F-32) / 9 (其中C表示攝氏溫度,F表示華氏溫度) 進行計算轉化。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double c,f;
scanf("%lf",&f);
c=5*(f-32)/9;
printf("%.5lf",c);
return 0;
}
1.3.9
描述
給出圓的半徑,求圓的直徑、周長和面積。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double r,d,c,s;
const double Pi=3.14159;
scanf("%lf",&r);
d=2*r;
c=d*Pi;
s=Pi*r*r;
printf("%.4lf %.4lf %.4lf",d,c,s);
return 0;
}
1.3.10
描述
對於阻值為r1和r2的電阻,其並聯電阻阻值公式計算如下:
R = 1/(1/r1 + 1/r2)
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double r1,r2,R;
scanf("%lf%lf",&r1,&r2);
R=1/(1/r1+1/r2);
printf("%.2lf",R);
return 0;
}
1.3.11
描述
計算兩個雙精度浮點數a和b的相除的余數,a和b都是正數的。這里余數(r)的定義是:a = k * b + r,其中 k是整數, 0 <= r < b。
#include<cstdio>
using namespace std;
int main()
{
double a,b,r;
int k;
scanf("%lf%lf",&a,&b);
k=a/b;
r=a-k*b;
printf("%g",r);
return 0;
}
1.3.12
描述
對於半徑為r的球,其體積的計算公式為V=4/3*πr3,這里取π= 3.14。
現給定r,求V。
#include<cstdio>
using namespace std;
int main()
{
double r,v;
scanf("%lf",&r);
v=(double)4/3*3.14*r*r*r;
printf("%.2lf",v);
return 0;
}
1.3.13
描述
將一個三位數反向輸出。
#include<iostream>
using namespace std;
int main()
{
int a;
cin>>a;
cout<<a%10<<a/10%10<<a/100;
return 0;
}
1.3.14
描述
一只大象口渴了,要喝20升水才能解渴,但現在只有一個深h厘米,底面半徑為r厘米的小圓桶(h和r都是整數)。問大象至少要喝多少桶水才會解渴。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int h,r,t;
double v,pi=3.14159;
cin>>h>>r;
v=h*r*r*pi/1000;
t=20/v+1;
cout<<t;
return 0;
}
1.3.15
描述
你買了一箱n個蘋果,很不幸的是買完時箱子里混進了一條蟲子。蟲子每x小時能吃掉一個蘋果,假設蟲子在吃完一個蘋果之前不會吃另一個,那么經過y小時你還有多少個完整的蘋果?
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,x,y,s;
cin>>n>>x>>y;
s=n-(double)y/x;
cout<<s;
return 0;
}
1.3.16
描述
已知線段的兩個端點的坐標A(Xa,Ya),B(Xb,Yb),求線段AB的長度。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double xa,ya,xb,yb,s;
scanf("%lf%lf%lf%lf%",&xa,&ya,&xb,&yb);
s=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
printf("%.3lf",s);
return 0;
}
1.3.17
描述
平面上有一個三角形,它的三個頂點坐標分別為(x1, y1), (x2, y2), (x3, y3),那么請問這個三角形的面積是多少。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
float x1,y1,x2,y2,x3,y3;
double a,b,c,p,s;
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("%.2lf",s);
return 0;
}
1.3.18
描述
給出一個等差數列的前兩項a1,a2,求第n項是多少。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int a1,a2,n,s;
cin>>a1>>a2>>n;
s=(a2-a1)*(n-1)+a1;
cout<<s;
return 0;
}
1.3.19
描述
輸入兩個正整數A和B,求A*B。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
unsigned int a,b;
cin>>a>>b;
cout<<a*b;
return 0;
}
1.3.20
描述
給定非負整數n,求2^n。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n,a=1;
cin>>n;
for(int i=1;i<=n;i++)
a=a*2;
cout<<a;
return 0;
}