计算正五边形的周长和面积
#include <bits/stdc++.h>
using namespace std;
int main()
{
double n,S,C;
double a,b;
cin>>n;
a=sqrt(5);
b=25+10*a;
S=sqrt(b)/4*n*n;
cout<<S<<endl;
C=5*n;
cout<<C<<endl;
return 0;
}
计算长方形面积和表面积
#include<iostream>
#include<string>
using namespace std;
int area(int x,int y)
{
int a;
a=x*y;
return a;
}
int area(int x,int y,int z)
{
int m,n,h,sum;
m=x*y;
n=x*z;
h=y*z;
sum=(m+n+h)*2;
return sum;
}
int main()
{
int i, repeat, c, x, y, z;
cin>>repeat;
for(i=0;i<repeat;i++){
cin>>c;
if(c==2){
cin>>x>>y;
cout<<area(x,y)<<endl;
}
if(c==3){
cin>>x>>y>>z;
cout<<area(x,y,z)<<endl;
}
}
return 0;
}