Showing posts with label TEMPERATURE CONVERTER. Show all posts
Showing posts with label TEMPERATURE CONVERTER. Show all posts

Simple Conversion Program in C

How to write a Simple Conversion Program in C Programming Language ?

This is Simple Conversion Program in C Programming.


1. Temperature converter
2. Distance converter


Temperature conversion list


1. Convert Celsius to Fahrenheit 
2. Convert Fahrenheit to Celsius

Output: What is the degrees in Celsius?
Output: What is the degrees in Fahrenheit?

Distance conversion list

1. Convert Inches to Centimetres
2. Convert Centimetres to Inches
3. Convert Feet to Meters
4. Convert Meters to Feet

Output: What is the distance in Inches?
Output: What is the distance in Centimetres?
Output: What is the distance in feet?
Output: What is the distance in meters?


Solution:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /* README
  4.     A simple conversion program
  5.     Coded by SmakGezgo
  6. */
  7. int main()
  8. {
  9.     // Main program select
  10.     int list;
  11.     int con;
  12.     printf("Select a list:\n 1. Temperature converter\n 2. Distance converter\n");
  13.     scanf( "%d", &list);
  14.     // Temperature conversion list
  15.     if(list == 1){
  16.         printf("Select a converter:\n 1. Celsius to Fahrenheit\n 2. Fahrenheit to Celsius\n");
  17.         scanf( "%d", &con);
  18.     // Fahrenhiet to Celsius
  19.         if(con == 1){
  20.             int cel;
  21.             printf("What is the degrees in Celsius? \n");
  22.             scanf("%d", &cel);
  23.         int fah = (cel * 1.8) + 32;
  24.         printf("%d degrees Celsius is equal to %d degrees Fahrenheit. \n", cel, fah);
  25.         }
  26.     // Celsius to Fahrenhiet
  27.         else if(con == 2){
  28.             int fah;
  29.             printf("What is the degrees in Fahrenheit? \n");
  30.             scanf("%d", &fah);
  31.         int cel = (fah - 32) * .5556;
  32.         printf("%d degrees Fahrenheit is equal to %d degrees Celsius. \n", fah, cel);
  33.         }
  34.     }
  35.     // Distance conversion list
  36.     if(list == 2){
  37.         printf("Select a converter:\n 1. Inches to Centimetres\n 2. Centimetres to Inches\n 3. Feet to Meters\n 4. Meters to Feet\n");
  38.         scanf( "%d", &con);
  39.     // Inches to Centimeters
  40.         if(con == 1){
  41.             float in;
  42.             printf("What is the distance in Inches? \n");
  43.             scanf("%f", &in);
  44.         float cm = (in * .39);
  45.         printf("%.2f Inches is equal to %.2f Centimetres. \n", in, cm);
  46.         }
  47.     // Centimeters to Inches
  48.         if(con == 2){
  49.             float cm;
  50.             printf("What is the distance in Centimetres? \n");
  51.             scanf("%f", &cm);
  52.         float in = (cm * 2.54);
  53.         printf("%.2f Centimetres is equal to %.2f Inches. \n", cm, in);
  54.         }
  55.     // Feet to Meters
  56.         if(con == 3){
  57.             float ft;
  58.             printf("What is the distance in feet? \n");
  59.             scanf("%f", &ft);
  60.         float m = (ft / 3.2808);
  61.         printf("%.2f feet is equal to %.2f meters. \n", ft, m);
  62.         }
  63.     // Meters to Feet
  64.         if(con == 4){
  65.             float m;
  66.             printf("What is the distance in meters? \n");
  67.             scanf("%f", &m);
  68.         float ft = (* 3.2808);
  69.         printf("%.2f meters is equal to %.2f feet. \n", m, ft);
  70.         }
  71.     }
  72.     return 0;
  73. }

Celsius to Fahrenheit, Fahrenheit to Celsius and Kelvin to Fahrenheit

How to write a C Program to Convert Celsius to Fahrenheit, Fahrenheit to Celsius and Kelvin to Fahrenheit in C Programming Language ?

This C Program Change given temperature into Celsius to Fahrenheit, Fahrenheit to Celsius and Kelvin to Fahrenheit.

Temperature (F,C,K) is enter by the user through keyboard.

Solution:


  1. #include <stdio.h>
  2. int main(int argc, char **argv)
  3. {
  4.     float temp=0;
  5.     float kelvin=0;
  6.     float celsius=0;
  7.     float fahrenheit=0;
  8.     char unit;
  9.         printf("Enter a temperature number\n");
  10.     scanf("%f", &temp);
  11.     printf("you entered %f, what unit are you using(F,C,K)", temp);
  12.     scanf("%c,", &unit);
  13.     printf("%c."&unit);
  14.     if(unit=='c'){
  15.                 kelvin=temp-273.15;
  16.                 fahrenheit=temp*9/5+32;
  17.                 printf("%f Celsius =%f Fahrenheit and %f Kelvin", temp, fahrenheit, kelvin);
  18.         }
  19.         else if(unit=='f'){
  20.                 celsius=(fahrenheit-32)*5/9;
  21.                 kelvin=celsius-273.15;
  22.                 printf("%f Fahrenheit =%f Celsius and %f Kelvin", temp, fahrenheit, kelvin);
  23.         }
  24.         else if(unit=='k'){
  25.                 celsius=temp+273.15;
  26.                 fahrenheit=celsius*9/5+32;
  27.                 printf("%f Kelvin =%f fahrenheit and %f celsius", temp,fahrenheit, celsius);
  28.         }
  29.         else{
  30.                 printf("\n why did you do this");
  31.         }
  32.         return 0;
  33. }

C Program to Convert Celsius Temperature into Fahrenheit Temperature

How to write a C Program Convert Celsius Temperature into Fahrenheit Temperature in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6.         float C, F;
  7.  
  8.         for (= 0; C <= 100; C++)
  9.                
  10.                 printf("Celsius: %6.2lf\n", C);        
  11.  
  12.                 F = 32 + ((9 / 5)*C);
  13.                 printf("Fahrenheit: %6.2lf\n", F);
  14.  
  15.         return 0;
  16. }