*Example of a program without functions*/
/*temperature conversion program*/
#include <stdio.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
int main()
{
int answer_1;
double celsius;
double fahr;
answer_1=TRUE;
while(answer_1==TRUE) {
printf("\nInput degrees Fahrenheit for conversion to Celsius (^z to exit): \n");
scanf("%lf",&fahr);
celsius=((fahr-32.0)*5.)/9.;
printf("\n%lf Celcius\n\n", celsius);
printf("\nAnother F to C conversion? (0 to exit conversion): \n");
scanf("%d", &answer_1);
}
printf("\nDo you want to input degrees in Celsius for conversion? (yes=1)\n");
scanf("%d", &answer_1);
while(answer_1==TRUE) {
printf("\n\nInput degrees Celsius for conversion to Fahrenheit (^z to exit): \n");
scanf("%lf",&celsius);
fahr=(9.0/5.0)*celsius+32.0;
printf("\n\n%lf Fahrenheit. \n\n",fahr);
printf("\nAnother C to F conversion? (0 to exit conversion): \n");
scanf("%d", &answer_1);
}
printf("\n\nEnd of program \n");
return (0);
}
No comments:
Post a Comment