Thursday, 26 January 2012

Write a c program which gives you the temperature in Centigrade and in Fahrenheit

#include<stdio.h>
#include<conio.h>

void centigrade();
void fahrenheit();

void main()
{
    int ch;
    char choice;
    do
    {
    clrscr();
    printf("Press 1 for Fahrenheit\n");
    printf("Press 2 for Centigrade\n");
    printf("Enter your choice:");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:
    centigrade();
    break;

    case 2:
    fahrenheit();
    break;

    default:
    printf("You have Entered wrong choice....\n");

    }
    printf("\nIf u want to continue then press y\n");
    choice=getch();
    if(choice!='y')
    break;
    else
    continue;
    }
    while(1);

    getch();
}

void centigrade()
{
    float c,f;
    printf("Enter the fahrenheit degrees:");
    scanf("%f", &f);
    c= (f-32)/1.8 ;
    printf("\nAfter Fahrenheit degrees, Centigrade Degrees = %f", c);
}

void fahrenheit()
{
    float c,f;
    printf("Enter the Centigrade degrees:");
    scanf("%d",&c);
    f= 1.8*c + 32.0;
    printf("\nAfter Centigrade degrees, Fahrenheit degrees = %f", f);
}

No comments:

Post a Comment