目录
01:A+B问题
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
return 0;
}
02:计算(a+b)*c的值
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<(a+b)*c;
return 0;
}
03:计算(a+b)/c的值
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
c!=0;
cin>>a>>b>>c;
cout<<(a+b)/c;
return 0;
}
04:带余除法
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a/b<<" "<<a%b;
return 0;
}
05:计算分数的浮点数值
#include <bits/stdc++.h>
using namespace std;
int main()
{
double a,b;
b!=0;
cin>>a>>b;
cout<<fixed<<setprecision(9)<<a/b;
return 0;
}
06:甲流疫情死亡率
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y;
scanf("%d%d",&x,&y);
double z;
z=(y*1.0/x)*100;
printf("%.3lf%%\n",z);
system("pause");
return 0;
}
07:计算多项式的值
#include <bits/stdc++.h>
using namespace std;
int main()
{
double C,F;
cin>>F;
F>=459.67;
C = 5 * (F-32) / 9;
cout<<fixed<<setprecision(5)<<C;
return 0;
}
09:与圆相关的计算
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double r;
cin>>r;
double d,c,s,pi;
pi=3.14159;
d=2*r;
c=2*pi*r;
s=pi*r*r;
cout<<fixed<<setprecision(4)<<d<<" "<<c<<" "<<s<<endl;
}
10:计算并联电阻的阻值
#include <bits/stdc++.h>
using namespace std;
int main()
{
float r1,r2,R;
cin>>r1>>r2;
R=1/(1/r1+1/r2);
cout<<fixed<<setprecision(2)<<R;
return 0;
}
11:计算浮点数相除的余数
#include <bits/stdc++.h>
using namespace std;
int main( )
{
double a,b,r;
int k;
cin>>a>>b;
k=(int)(a/b);
r=a-k*b;
cout<<r;
return 0;
}
12:计算球的体积
#include <bits/stdc++.h>
using namespace std;
int main( )
{
double r,s;
cin>>r;
s=4.0/3*3.14*r*r*r;
cout<<fixed<<setprecision(2)<<s;
return 0;
}
13:反向输出一个三位数
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,bai,shi,ge;
cin>>n;
bai=n/100;
shi=n/10%10;
ge=n%10;
cout<<ge<<shi<<bai;
return 0;
}
14:大象喝水
#include <bits/stdc++.h>
using namespace std;
int main( )
{
int n;
long double h,r,v;
cin>>h>>r;
v=3.14159*r*r*h;
n=int(20000/v);
if(20000/v>0)
{
n++;
cout<<n;
}
else
{
cout<<n;
}
return 0;
}
15:苹果和虫子
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y,i,j;
cin>>n>>x>>y;
j=y%x;
if(j!=0) j=y/x+1;
else j=y/x;
if(j>n)
cout<<"0";
else
{
i=n-j;
cout<<i;
}
}
16:计算线段长度
#include <bits/stdc++.h>
using namespace std;
int main( )
{
double x1,x2,y1,y2,t;
scanf("%lf %lf",&x1,&y1);
scanf("%lf %lf",&x2,&y2);
t=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<fixed<<setprecision(3)<<t;
return 0;
}
17:计算三角形面积
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double x1,x2,x3,y1,y2,y3,p,s,a,b,c;
cout.precision(2);
cin>>x1>>y1>>x2>>y2>>x3>>y3;
a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
cout<<fixed<<s;
return 0;
}
18:等差数列末项计算
#include <bits/stdc++.h>
using namespace std;
int main( )
{
int a,b,n;
cin>>a>>b>>n;
int d=b-a;
cout<<a+(n-1)*d;
return 0;
}
19:A*B问题
#include <iostream>
using namespace std;
int main()
{
long long a,b;
cin>>a>>b;
1<=a,b<=50000;
cout<<a*b;
return 0;
}
20:计算2的幂
#include <iostream>
using namespace std;
int main()
{
int a[100],n,k;
cin>>n;
a[0]=1;
a[1]=1;
for(int i=1;i<=n;i++)
{
k=0;
for(int j=1;j<=a[0];j++)
{
a[j]=a[j]*2+k;
k=a[j]/10;
a[j]%=10;
}
if(k>0)
{
a[0]++;
a[a[0]]=k;
}
}
for(int i=a[0];i>0;i--)
cout<<a[i];
return 0;
}
本文含有隐藏内容,请 开通VIP 后查看