當前位置:首頁 » 編程語言 » c語言輸入英尺顯示身高
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言輸入英尺顯示身高

發布時間: 2022-08-06 12:36:12

A. c語言中關於英尺、英寸、厘米的換算

(foot+inch/12)*0.3048 = cm / 100

foot+inch/12 = cm / (100 * 0.3048) = cm / 30.48

因為1foot = 12inch,所以inch / 12 < 1,所以foot = cm/30.48的整數部分 inch / 12 = cm/30.48的小數部分。

六七行就是完成這個功能。

(1)c語言輸入英尺顯示身高擴展閱讀:

一、英尺和英寸的知識

1、1碼 = 3英寸 ,1英尺 = 12 英寸;

2、碼英文字母是 yard

3、英尺英文字母是 foot( 單數 ) feet( 復數 )

4、英寸英文單詞是 inch ( 單數 )inches( 復數 )

二、長度單位轉換

#include<stdio.h>

#define Mile_to_meter 1609 //1英里 = 1690米

#define Foot_to_centimeter 30.48 //1英里 = 1690米

#define Inch_to_centimeter 2.54 //1英里 = 1690米

int main(){

float mile, foot, inch;

scanf("%f%f%f", &mile, &foot, &inch);

printf("%fmiles = %f meters ", mile, mile * Mile_to_meter);

printf("%ffeet = %f centimeters ", foot, foot * Foot_to_centimeter );

printf("%finches = %f centimeters ", inch, inch * Inch_to_centimeter );

return 0;
}

B. c語言程序求解

前兩個你的第四行printf語句不能換行的啊
要不就像第三張一樣,分兩個printf:printf("請分別輸入身高的英尺和英寸,");
printf("如輸入:5 7表示5英尺7英寸");
如果你一定要用一個printf的話 就不要換行 像這樣:
printf("請分別輸入身高的英尺和英寸,如輸入:5 7表示5英尺7英寸");
堅決不能這樣:
printf("請分別輸入身高的英尺和英寸,"
"如輸入:5 7表示5英尺7英寸");
因為電腦是一行一行識別的 所以它會先單獨識別第四行 第五行 一堆字 卻沒有printf自然編譯錯誤了

C. c語言編程,輸入:一個正整數的厘米數 輸出:對應的英尺數和英寸數,中間用空格分開

#include <stdio.h>

void main()

{

int x;

float y1,y2;

scanf("%d",&x);

y1=x/2.54;

y2=y1/12;

printf("%d cm = %.2f inch = %.2f feet ",x,y1,y2);

getch();

return 0;

}

D. C語言編程題:輸入某人的身高(以厘米為單位,如174cm),將身高(以米為單位,如1.74m)輸出在屏幕上

//功能描述:1.計算人體指數

//體指數計算公式:t=w/h^2

//輸入參數:

//1.w:體重(公斤),數據類型為整型;

//2.h:身高(厘米),數據類型為整型;

//完成時間:2015年3月24日

//============================================//

//==========子函數floatcountBodyIndex(intbodyWeight,intbodyheight)

#include<stdio.h>

#include<stdlib.h>

floatcountBodyIndex(intbodyWeight,intbodyHeight)

{

//先對調用的參數進行檢查

if(bodyWeight<=0&&bodyHeight<=0)

{

printf("輸入的體重或身高錯誤,請檢查! ");

}

else

{

//將輸入的身高、體重、體指數輸出到屏幕上

printf("體重:%d(斤) ",bodyWeight*2);

printf("身高:%.2f ",bodyHeight/100.0);

}

return(bodyWeight*2)/(bodyHeight/100.0);

}

//==========主函數intmain(void)

intmain(void)

{

intbodyWeight,bodyHeight;

floatbodyIndex;printf("請輸入體重(公斤),身高(厘米): ");

scanf("%d%d",&bodyWeight,&bodyHeight);bodyIndex=countBodyIndex(bodyWeight,bodyHeight);

printf("體指數是:%.2f。 ",bodyIndex);system("pause");return0;

}

E. C語言編程問題

#include <stdio.h>


#define YCZHYC 12


#define YCZHLM 2.54


int main(void)


{


int yc1,yc2;


printf(" 請輸入身高(英尺及英寸數據之間用空格隔開):");


scanf("%d %d",&yc1,&yc2);


printf(" %d 英尺 %d 英寸的身高轉換為公制為:%.2f m",yc1,yc2,(double)(yc1*YCZHYC+yc2)*YCZHLM/100);


return 0;


}

F. c++編程問題,輸入你的身高(單位是cm),轉換成英尺和英寸顯示。

#include<iostream>
using namespace std;
const double inch=0.39;
const double foot=0.03;
int main()
{
cout.setf(ios_base::fixed,ios_base::floatfield);
int cm;
double myinch,myfoot;
cout<<"輸入你的身高(CM)___\\b\\b\\b";
cin>>cm;
myinch=inch*cm;
myfoot=foot*cm;
cout<<"你的身高是"<<cm<<"cm,"<<myinch<<"\
inch,"<<myfoot<<"foot"<<endl;
return 0;
}

/*程序的順序寫錯了,在執行
myinch=inch*cm;
myfoot=foot*cm;
如果你沒有對cm賦予初值那麼編譯器就會隨機的給他一個初值來完成此語句的執行。那麼就會得不到你想要的結果。你的主函數是有返回值的,最好給他一個返回值,雖然不加也可以,但是當你寫大程序的時候,警告的東西好、就會多起來,處理起來不好,加個返回語句,程序看起來比較整齊,這也是養成良好編程習慣的一種哦。*/

G. 用C語言編寫身高單位轉換:鍵盤輸入一個英制身高(幾英尺幾英寸),計算對應的公

你是問英制轉公制:
一、公式1英尺=12英寸,1英寸=2.54厘米。
二、定義兩個浮點數變數表示英尺和英寸,輸入後,套上面公式算即可。
比如:
#include<stdio.h>
int main()
{
float feet,inch,meter;
printf("輸入身高英尺 英寸:");
scanf("%f%f",&feet,&inch);
meter=(feet*12+inch)*2.54*100;
printf("轉換後%f米\n",meter);
return 0;
}
//ps:手機打代碼,自行退格調整對齊。

H. 用C語言編寫一個輸入身高(cm)輸出身高英寸

#include <stdio.h>

int main()

{

float height = 0;

printf("請輸入身高單位是厘米: ");

scanf("%f", &height);

printf("身高為 %f英寸 ", height/2.54);

return 0;

}

(8)c語言輸入英尺顯示身高擴展閱讀:

1碼=3英尺=0.9144米

1英尺=12英寸=30.48厘米

英寸(inch,in) :1英寸=2.54厘米。

scanf()是C語言中的一個輸入函數。與printf函數一樣,都被聲明在頭文件stdio.h里,因此在使用scanf函數時要加上#include <stdio.h>。

在stdio.h頭文件中內置了幾種輸入輸出函數,如下列出:

printf 與 scanf

getchar 與 putchar

gets 與 puts

格式控制:由「%」後跟格式字元組成。將輸出數據轉換為指定格式輸出,字元串原樣輸出,轉義字元對輸出形式進行控制。

參考資料來源:網路-scanf函數