一個完整的C程式
阿新 • • 發佈:2019-01-01
Visual Studio 2013
#include<stdio.h> //包含標頭檔案
#define HEG 0.54 //定義常亮
float height(float father, float mother); //函式宣告
int main() //主函式main
{
float father; //定義浮點型變數,表示父親的身高
float mother; //定義浮點型變數,表示母親的身高
float son; //定義浮點型變數,表示兒子的身高
printf("請輸入父親的身高:\n"); //顯示提示
scanf_s("%f", &father); //輸入父親的身高
printf("請輸入母親的身高:\n"); //顯示提示
scanf_s("%f", &mother); //輸入母親的身高
son = height(father, mother); //呼叫函式,計算兒子的身高
printf("預測兒子的身高為:"); //顯示提示
printf("%.2f\n", son); //輸出兒子的身高
return 0; //返回整型0
}
float height(float father, float mother) //定義計算兒子身高的函式
{
float son = (father + mother)*HEG; //具體計算兒子的身高
return son; //返回兒子的身高
}
Caesar盧尚宇 [email protected]
2018年12月27日