『壹』 求c語言程序 輸入磅的重量數,換算成千克單位 程序中要有輸入輸出提示句
按照題目要求編寫的磅轉換為千克的C語言程序如下
#include<stdio.h>
int main(){
float lb,kg;
printf("請輸入磅的重量數:");
scanf("%f",&lb);
kg=lb*453.6/1000;
printf("%f磅等於%f千克",lb,kg);
return 0;
}
『貳』 使用C語言編寫自定義函數,通過函數調用實現多種單位轉換應用功能.
#include<stdio.h> void sort(int a[], int size) { int i,j; for(i=0;i<size-1;i++) for(j=0;j<size-i-1;j++) if(a[j]>a[j+1]) { int t; t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } main() { int i,a[10]; for(i=0;i<10;i++) scanf("%d",&a[i]); sort(a,10); for(i=0;i<10;i++) printf("M",a[i]); printf("\n"); } 函數sort實現冒泡排序
『叄』 用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:手機打代碼,自行退格調整對齊。
『肆』 用C語言編寫一個簡單的長度轉換程序(m,mm,cm,km)
#include<stdio.h>
#include<iostream.h>
intmain()
{
doublenum;
doublen;
doublem;
while(true)
{
cout<<"請選擇要輸入的單位:1、毫米;2、厘米;3、米;4、千米"<<endl;
cin>>num;
cout<<"請輸入單位長度"<<endl;
cin>>m;
if(num==1)
{
cout<<"請選擇要轉換的單位:1、厘米;2、米;3、千米"<<endl;
cin>>n;
if(n==1)
{
cout<<"毫米轉換成厘米結果為:"<<m<<"mm="<<m/100<<"cm;"<<endl;
}elseif(n==2){
cout<<"毫米轉換成米結果為:"<<m<<"mm="<<m/1000<<"m;"<<endl;
}elseif(n==3){
cout<<"毫米轉換成千米結果為:"<<m<<"mm="<<m/1000000<<"km;"<<endl;
}else{
cout<<"輸入有誤,請重新輸入"<<endl;
continue;
}
}elseif(num==2){
cout<<"請選擇要轉換的單位:1、毫米;2、米;3、千米"<<endl;
cin>>n;
if(n==1)
{
cout<<"厘米轉換成毫米結果為:"<<m<<"cm="<<m*100<<"mm;"<<endl;
}elseif(n==2){
cout<<"厘米轉換成米結果為:"<<m<<"cm="<<m/10<<"m;"<<endl;
}elseif(n==3){
cout<<"厘米轉換成千米結果為:"<<m<<"cm="<<m/10000<<"km;"<<endl;
}else{
cout<<"輸入有誤,請重新輸入"<<endl;
continue;
}
}elseif(num==3){
cout<<"請選擇要轉換的單位:1、毫米;2、厘米;3、千米"<<endl;
cin>>n;
if(n==1)
{
cout<<"米轉換成毫米結果為:"<<m<<"m="<<m*1000<<"mm;"<<endl;
}elseif(n==2){
cout<<"米轉換成厘米結果為:"<<m<<"m="<<m*10<<"cm;"<<endl;
}elseif(n==3){
cout<<"米轉換成千米結果為:"<<m<<"m="<<m/1000<<"km;"<<endl;
}else{
cout<<"輸入有誤,請重新輸入"<<endl;
continue;
}
}elseif(num==4){
cout<<"請選擇要轉換的單位:1、毫米;2、厘米;3、米"<<endl;
cin>>n;
if(n==1)
{
cout<<"千米轉換成毫米結果為:"<<m<<"km="<<m*1000*1000<<"mm;"<<endl;
}elseif(n==2){
cout<<"千米轉換成厘米結果為:"<<m<<"km="<<m*10*1000<<"cm;"<<endl;
}elseif(n==3){
cout<<"千米轉換成米結果為:"<<m<<"km="<<m*1000<<"m;"<<endl;
}else{
cout<<"輸入有誤,請重新輸入"<<endl;
continue;
}
}else{
cout<<"輸入有誤,請重新輸入"<<endl;
continue;
}
}
return0;
}