Vous êtes sur la page 1sur 7

Convert the following flowchart to C program.

Start

Temperature1 Temperature2
This is temperature conversion
program.

Enter 1 to continue the program


Enter temperature Enter temperature
Enter 2 to terminate the program
In Fahrenheit In Celsius

Proceed

X Y

no
Text1
While (Proceed == 1)
Fahrenheit = (9/5) x Y+32
Celsius = (X-32) / (9/5)
yes
end
Please select conversion:

1 – Fahrenheit to Celsius
Temperature in Fahrenheit is:
2 – Celsius to Fahrenheit Temperature in Celsius is: Celsius Fahrenheit

yes

choice== 1 Temperature1 End of function


End of function

no
Text1
yes

choice == 2 Temperature2
1 Thank You!!!!!

no

Wrong selection, please enter 1 or End of function


2 only!!!!!
Coding

# include <stdio.h>
float temp1 (float x);
float temp2(float y);
text1();
main ()
{int proceed=1;
printf("*****||This is temperature conversion program||*****\n\n");
printf("Enter 1 to continue the program\n");
printf("Enter 2 to terminate the program\n");
scanf("%d",&proceed);
while(proceed ==1)
{ float temp_celsius,temp_fahrenheit;
int choice;

printf("\nPlease select conversion\n");


printf("\n 1 - Fahrenheit to Celsius\n");
printf("\n 2 - Celsius to Fahrenheit\n");
scanf("%d",&choice);
if (choice ==1)
{
printf ( "Enter temperature in Fahrenheit\n");
scanf ("%f",&temp_fahrenheit) ;
temp1(temp_fahrenheit) ;
}else if (choice ==2)
{
printf ( "Enter temperature in Celsius\n");
scanf ("%f",&temp_celsius) ;
temp2(temp_celsius) ;
}else
printf("wrong selection, please enter 1 or 2 only");
printf("\nEnter 1 to proceed the program\n");
printf("Enter 2 to terminate the program\n");
scanf("%d",&proceed);
}
text1();
}
float temp1(float x)
{
float celsius=0 ;
celsius = (x - 32) / (1.8) ;
printf ( "\nTemperature in celsius is = %f", celsius) ;
printf ( "C");
}
float temp2(float y)
{float fahrenheit=0 ;
fahrenheit = (y*1.8)+32;
printf ( "\nTemperature in Fahrenheit is = %f",fahrenheit);
printf ( "F");
}
text1()
{
printf("\nThank You!!!\n");
}
Results

User enters 1 to continue the program.

User enters 1.
User enters temperature in Fahrenheit 32.

User enters 1.

User enters 2.
User enters temperature in Celsius 0.

Then user terminates the program by entering 2.

Vous aimerez peut-être aussi