當前位置:編程學習大全網 - 編程語言 - C語言編程 溫度轉換程序 從300度到0度 for語句 和while語句的

C語言編程 溫度轉換程序 從300度到0度 for語句 和while語句的

可以進行攝氏、華氏、開爾文轉換的C程序,在TC下編譯運行。

#include <stdio.h>

#include <conio.h>

int main()

{

int i,j;

char choice;

float celsius,fahrenheit,kelvin;

clrscr();

printf(" *****************************************************\n");

printf(" * 1. Celsius change into Fahrenheit *\n");

printf(" * 2. Fahrenheit change into Celsius *\n");

printf(" * 3. Celsius change into Kelvin *\n");

printf(" * 4. Exit *\n");

printf(" *****************************************************\n\n");

printf(" Please your choice(1-4): ");

while(1)

{

scanf("%c",&choice);

if(choice>='1' && choice<='4')

{

printf("\n");

i=(int)(choice-'0');

switch(i)

{

case 1:

{

printf(" Please input Celsius: ");

scanf("%f",&celsius);

fahrenheit=celsius*9.0/5+32.0;

printf("\n");

printf(" The Fahrenheit is: %5.2f\n\n",fahrenheit);

break;

}

case 2:

{

printf(" Please input Fahrenheit: ");

scanf("%f",&fahrenheit);

celsius=(fahrenheit-32.0)*5.0/9;

printf("\n");

printf(" The Celsius is: %5.2f\n\n",celsius);

break;

}

case 3:

{

printf(" Please input Celsius: ");

scanf("%f",&celsius);

kelvin=celsius+273.15;

printf("\n");

printf(" The Kelvin is: %5.2f\n\n",kelvin);

break;

}

case 4: exit(0);

}

printf(" Please press any key to continue...");

getch();

for(j=9;j<=19;j++)

{

gotoxy(1,j);

clreol();

}

gotoxy(28,8);

clreol();

continue;

}

else

{

gotoxy(28,8);

clreol();

gotoxy(28,8);

continue;

}

}

return 0;

}

  • 上一篇:自我評價的簡要總結[5篇]
  • 下一篇:IP核是什麽
  • copyright 2024編程學習大全網