Advertisement
Realratnadwip

C to F, F to C

May 21st, 2025
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6.     int choice;
  7.     float temp, result;
  8.  
  9.     printf("This is a simple program to convert temperature.\n\n");
  10.     printf("Choose an option:\n");
  11.     printf("1 - Convert Celsius to Fahrenheit\n");
  12.     printf("2 - Convert Fahrenheit to Celsius\n\n");
  13.     printf("Enter your choice : ");
  14.     scanf("%d", &choice);
  15.  
  16.     if(choice == 1)
  17.     {
  18.         printf("\nEnter temperature in Celsius : ");
  19.         scanf("%f", &temp);
  20.         result = (temp * 9 / 5) + 32;
  21.         printf("\n%.2f Celsius = %.2f Fahrenheit", temp, result);
  22.     }
  23.     else if(choice == 2)
  24.     {
  25.         printf("\nEnter temperature in Fahrenheit : ");
  26.         scanf("%f", &temp);
  27.         result = (temp - 32) * 5 / 9;
  28.         printf("\n%.2f Fahrenheit = %.2f Celsius", temp, result);
  29.     }
  30.     else
  31.     {
  32.         printf("\nInvalid choice. Please run the program again and enter 1 or 2.");
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement