Have a Read!

Hi Everyone.
The idea for this page is to provide new c users simple c tutorials to learn how to develop the logic and more importantly correct way to write syntax.
ENJOY !!!

Wednesday, January 26, 2011

C PROGRAM FOR BASIC FORMULAS

/*this program can solve formulas:
1)force=mass*acceleration        2)coversion of litres in gallons      3)conversion of km in meters
this program will display a menu and its your choice which formula you want to use*/
#include<stdio.h>
int main()
{
float choice;
float mass;
float acc;
float force;
float lt;
float gall;
float meter;
float km;
printf("which formula do you want to use\n\n1)force=mass*acceleration\n2)conversion of litres of petrol in gallons\n3)conversion of distance in km into meters\n");
printf("\nenter a choice 1,2 or 3\n");
scanf("%f",&choice); /*this will take a number from user that which formula he want to solve*/
if(choice==1 || choice==2 || choice==3)     /*this if statement makes sure that choice entered is 1,2
                                              or 3*/                    
{
  if(choice==1)     /*this statement wil execute if the user enters 1 coice which is to find force*/
  {
   printf("enter mass\n");
   scanf("%f",&mass);
   printf("enter acceleration\n");
   scanf("%f",&acc);
   force=mass*acc;
   printf("force is %f\n",force);
  }
  if(choice==2)     /*this statement wil execute if the user enters 2 coice*/
  {
   printf("enter volume of petrol in litres\n");
   scanf("%f",&lt);
   gall=lt*0.264172052358148;
   printf("volume of petrol in gallons is %f\n",gall);
  }
  if(choice==3)    /*this statement wil execute if the user enters 3 coice*/
  {
   printf("enter distance in km\n");
   scanf("%f",&km);
   meter=km*1000;
   printf("distance in meters is %f\n",meter);
  }
}
else            /*this else is with the first if statement*/
printf("you have entered a wrong choice\n");
return 0;
}

No comments:

Post a Comment

Related Posts with Thumbnails