Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void main()
- {
- int choice;
- float temp, result;
- printf("This is a simple program to convert temperature.\n\n");
- printf("Choose an option:\n");
- printf("1 - Convert Celsius to Fahrenheit\n");
- printf("2 - Convert Fahrenheit to Celsius\n\n");
- printf("Enter your choice : ");
- scanf("%d", &choice);
- if(choice == 1)
- {
- printf("\nEnter temperature in Celsius : ");
- scanf("%f", &temp);
- result = (temp * 9 / 5) + 32;
- printf("\n%.2f Celsius = %.2f Fahrenheit", temp, result);
- }
- else if(choice == 2)
- {
- printf("\nEnter temperature in Fahrenheit : ");
- scanf("%f", &temp);
- result = (temp - 32) * 5 / 9;
- printf("\n%.2f Fahrenheit = %.2f Celsius", temp, result);
- }
- else
- {
- printf("\nInvalid choice. Please run the program again and enter 1 or 2.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement