编写程序,求标准体重。
1.用户输入圆的半径,求其周长和面积。
2.男性:(身高cm-80)×70﹪=标准体重
女性:(身高cm-70)×60﹪=标准体重
用户输入性别和身高,求标准体重
1.
#include <stdio.h>
int main()
{
double r,l,s;
printf("请输入半径:");
scanf("%lf",&r);
l=2*3.1415*r;
s = 3.1415*r*r;
printf("周长=%lf,面积=%lf",l,s);
return 0;
}
2.
#include <stdio.h>
int main()
{
double height,ww;
char sex;
printf("请输入性别(F/M)和身高:");
scanf("%c %lf",&sex,&height);
if('f'==sex || 'F'==sex)
{
ww = (height-70)*0.6;
printf("女性,标准体重:%.2lf\n",ww);//保留2位小数
}
else if('m'==sex || 'M'==sex)
{
ww = (height-80)*0.7;
printf("男性,标准体重:%.2lf\n",ww);//保留2位小数
}
else
printf("性别输入错误\n");
return 0;
}
#include<iostream>
#define PI 3.1415926
using namespace std;
double perimeter(double radius) {//周长
return 2 * PI * radius;
}
double area(double radius) {//面积
return PI * radius * radius;
}
double standardHeight(int gender, double height) {//标准体重
if (gender == 0)//男性
return (height - 80) * 0.7;
else
return (height - 70) * 0.6;
}
int main() {
double radius,height;
int gender;
cout << "请输入圆的半径(cm)" << endl; cin >> radius;
cout << "该圆的周长" << perimeter(radius) << " 面积" << area(radius) << endl;
cout << "请输入用户的性别(0:表示男性,1:表示女性)" << endl; cin >> gender;
cout << "请输入用户的身高(cm)" << endl; cin >> height;
cout << "用户的标准体重是" << standardHeight(gender, height)<< "kg"<< endl;
}
1.输入圆的半径,求其周长和面积。
#include <iostream>
#include <cmath>
using namespace std;
const double PI = 3.14159; //定义一个常量PI #define PI 3.14159
int main()
{
int r;
double p, a;
cout << "请输入半径: ";
cin >> r;
p = 2 * PI * r;
a = PI * pow(r, 2);
cout << "周长是 : " << p << endl;
cout << "面积是 : " << a << endl;
return 0;
}
2.输入性别和身高,求标准体重
#include<stdio.h>
void main()
{
/*男性 : (身高<公分> - 80) * 0.7 = 理想体重<公斤>
女性 : (身高<公分> - 70) * 0.6 = 理想体重<公斤> 正负10%良好*/
float x,y;
int i;
printf("请输入你的性别(如果为女输入1,男0):");
scanf("%d",&i);
if(1)
{
printf("请输入你的身高:");
scanf("%f",&x);
y=(x-70)*0.6;
printf("%.2f\n",y);
}
else
{
printf("请输入你的身高:");
scanf("%f",&x);
y=(x-80)*0.7;
printf("%.2f\n",y);
}
}