• Exercise 3.1 Convert temperatures


    Exercise 3-1. Write a program that will first allow a user to choose one of two options:
    1. Convert a temperature from degrees Celsius to degrees Fahrenheit.
    2. Convert a temperature from degrees Fahrenheit to degrees Celsius.
    the program should then prompt for the temperature value to be entered and output the new value that results
    from the conversion. to convert from Celsius to Fahrenheit you can multiply the value by 1.8 and then add 32.
    to convert from Fahrenheit to Celsius, you can subtract 32 from the value, then multiply by 5, and divide the
    result by 9

    ME:

     1 #include<stdio.h>
     2 int main(void)
     3 {
     4     double farenheit = 0;
     5     double centigrate = 0;
     6     int type = 0;
     7     
     8     //get the temperature
     9     printf ("please enter your temperature, 1 for farenheit or 2 for centigrate");
    10     scanf ("%d", &type);
    11     
    12     if (type = 1 ){
    13         printf("pls enter the number of your farenheit");
    14         scanf("%d", &farenheit);
    15         centigrate = (farenheit - 32)*5/9;
    16         printf("farenheit to centigrate is %d ", farenheit, centigrate);
    17     }
    18     else {
    19         printf("pls enter your number of centigrate");
    20         scanf("%d", &centigrate);
    21         centigrate = farenheit * 1.8 + 32;
    22         printf("farenheit to centigrate is %d", centigrate);    
    23         
    24     }
    25     
    26     return 0;
    27 }
    28  

    Original:

     1 #include<stdio.h>
     2 int main(void)
     3 {
     4     double farenheit = 0;
     5     double centigrate = 0;
     6     int type = 0;
     7     
     8     //get the temperature
     9     printf ("please enter your temperature, 1 for farenheit or 2 for centigrate");
    10     scanf ("%d", &type);
    11     
    12     if (type = 1 ){
    13         printf("pls enter the number of your farenheit");
    14         scanf("%d", &farenheit);
    15         centigrate = (farenheit - 32)*5/9;
    16         printf("farenheit to centigrate is %d ", farenheit, centigrate);
    17     }
    18     else {
    19         printf("pls enter your number of centigrate");
    20         scanf("%d", &centigrate);
    21         centigrate = farenheit * 1.8 + 32;
    22         printf("farenheit to centigrate is %d", centigrate);    
    23         
    24     }
    25     
    26     return 0;
    27 }
    28  
  • 相关阅读:
    iOS开发HTTP协议相关知识总结
    php的变量作用域
    ArcGIS Server 10.1发布要素服务(FeatureLayer server)时遇到的数据库注册问题
    ArcGIS for JavaScript 关于路径开发的一些记录(三)
    ArcGIS for JavaScript 关于路径开发的一些记录(二)
    学习小结(2014.62014.8)
    ArcGIS for JavaScript 关于路径开发的一些记录(一)
    【转载】javascript深入理解js闭包
    【小记录】关于dojo中的on事件
    虚拟多继承
  • 原文地址:https://www.cnblogs.com/xiaomi5320/p/4169707.html
Copyright © 2020-2023  润新知