開宗明義,先說本系統文章的寫作風格:盡量條列,並附上圖解及程式碼。開講:
#include <stdio.h>
double GetBmi(double, double);
int main()
{
char name[50] = "Alex Van"; // 姓名
double height = 169; // 身高
double weight = 67.5; // 體重
double bmi = GetBmi(weight, height); // 呼叫計算BMI函數
printf("name: %s\t\tBMI: %.2lf\n", name, bmi);
return 0;
}
double GetBmi(double weight, double height)
{
height = height / 100;
return weight / (height*height);
}
class Person:
def __init__(self, name: str, height: int, weight: float):
self.name: str = name
self.height: int = height
self.weight: float = weight
def get_bmi(self) -> float:
return self.weight / ((self.height / 100) ** 2)
me = Person(name="Alex Van", weight=67.5, height=169)
bmi = me.get_bmi()
print(f"name: {me.name}\t\tBMI: {round(bmi, 2)}")
class Person:
def __init__(self, name: str, height: int, weight: float):
self.name: str = name
self.height: int = height
self.weight: float = weight
self.bmi: float = self.weight / ((self.height / 100) ** 2)
me = Person(name="Alex Van", weight=67.5, height=169)
print(f"name: {me.name}\t\tBMI: {round(me.bmi, 2)}")