Introduction

The main purpose of this blog is to share our experience with the world and get experience from the world. This will be a new venture for us and we are sure, we shall learn a lot with it. we will try to Explore our mind which will be very helpful for all us. As from its name, its a blog covering all the topics. we will try to post all the interesting topics and give our opinion. Do give your point of view in comments.


"NAVIGATE VIA BLOG ARCHIVE ON RIGHT TO GET WHAT YOU ARE LOOKING FOR"


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