

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This c program includes necessary libraries and provides conversions and calculations based on user input for mass, acceleration, force, liters to gallons, gallons to liters, kilometers to meters, and meters to kilometers.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!
/In the very first step of program,the library will be included which will contain necessary information of commands i used in the program./
#include<stdio.h>
/second step is the declaration ,that main function of the program is integer type function/
int main()
/the program is written in the middle brackets{}/
{
/it is the declaration that variables are of which type/
float Mass,Accelaration,Force,litres,gallons,kilometers,meters; int p,u,v;
/topic of the user/
printf("CONVERSIONS AND USAGE OF FORMULA\n\n\n");
/following print command will display the menu for user/
printf("Which formula or conversion you want to use\nPress option number to choose any one\n"); printf("(1)Mass*Accelaration=?Force\n(2)liters of petrol=?gallons\n(3)kilometers=?meters\n");
scanf("%d",&p);
/now the if statements will decide that which formula or conversion to use/
if (p==1) { printf("calculation of Force from mass and accelaration\n"); printf("Please enter Mass and Accelaration\nMass="); scanf("%f",&Mass); printf("Accelaration="); scanf("%f",&Accelaration); Force=Mass*Accelaration;
/here the calculated force will be displayed as output/
printf("Force=%.3f\n",Force); }
if (p==2) { printf("which conversion you want to do\n( )litres into Gallons\n"); printf("(2)gallons into litres\n");
scanf("%d",&u); if (u==1) { printf("please give no.of litres\nlitres="); scanf ("%f",&litres); gallons=litres*(0.264172051242);
/here the no.of gallons will be displayed as output/
printf("Gallons=%.3f\n",gallons); }
else { printf("please give no.of gallons\nno.of gallons="); scanf("%f",&gallons); litres=gallons*(3.785);
/here the no.of litres will be displayed as output/
printf("litres=%.3f\n",litres); } }
if (p==3) { printf("which conversion you want to do\n(1)kilometers into meters\n"); printf("(2)meters into kilometers\n"); scanf("%d",&v); if(v==1) { printf("please enter no.of kilometers\nkilometers="); scanf("%f",&kilometers); meters=kilometers*(1000);
/here the no.of meters will be displayed as output/
printf("Meters=%.3f\n",meters); } else { printf("please enter no.of meters\nmeters="); scanf("%f",&meters); kilometers=(meters/(1000));
/here the no.of kilometers will be displayed as output/
printf("kilometers=%f",kilometers); } }
return 0;