Using the C programming tool(s) of choice, write a C program for each of the fol
ID: 3692941 • Letter: U
Question
Using the C programming tool(s) of choice, write a C program for each of the following problems: A metric ton is 35,273.92 ounces. Write a C program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as well as the number of boxes needed to yield 1 metric ton of cereal. Assume 17 ounces per box of cereal. Your program should allow the user to repeat this calculation as often as the user wishes. Many treadmills output the speed of the treadmill in miles per hour (mph) on the console, but most runners think of speed in terms of a pace. A common pace is the number of minutes and seconds per mile instead of mph. Write a C program that starts with a quantity in mph and converts the quantity into minutes and seconds per mile. As an example, the proper output for an input of 6.5 mph should be 9 minutes and 13.8 seconds per mile. If you need to convert a double to an int, which will discard any value after the decimal point, then you may use: intValue = (int)dblVal; An approximate value of pi can be calculated using the series given below: pi = 4 times [1 - 1/3 + 1/5 - 1/7 + 1/9... + (+|-1)/(2n + 1)] Write a C program to calculate the approximate value of pi using this series. The program takes an input n that determines the number of terms in the approximation of the value of pi and outputs the approximation. Include a loop that allows the user to repeat this calculation for new values n until the user says she or he wants to end the program. A liter is 0.264179 gallons. Write a C program that will read in the number of liters of gasoline consumed by the user's car and the number of miles traveled by the car and will then output the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon.Explanation / Answer
//Every printf function and comments will give u clear description of the program
#include <stdio.h>
float funct(float gl); // funtion prototype
#define float gpl=0.264179; // constanc of type float
int main() // main start here
{
float ounces,metrics,convert; // required values for conversion and other uses
int n; char c='y'; // character for repeating until user wishes to exit
printf("Question No 1:");
while(c!='n') // loop until user enter n
{
printf(" Enter the package weigh in ounces:");
scanf("%f",&ounces);
metrics=ounces/3527392; //calculating metric tons
printf(" ounces in metrics tons are:%f",metrics);
printf(" Number of boxes needed for one metric ton is:%d",3527392/17); //printing number of boxes for 1 m ton
printf(" Number of boxes needed for given total ounces is:%d",(int) (ounces/17)); // printing boxes for given m
printf("Enter y to continue n to exit Question No 1");
scanf("%c",&c);
}
printf(" Question No2: ");
printf("Look at this conversion Given value 6.5 in mph ");
convert=(1/6.5)*60; // converting to minutes
int minutes=(int) convert; // receiving minutes the integer value is minutes from 9.23
float seconds=(convert-minutes)*60; // getiing seconds i.e 0.23*60 13.8
printf("6.5 mph is %d minutes and %f seconds per mile",minutes,seconds);
printf(" Question No 3: ");
printf("Enter n for number of repetations: ");
scanf("%d",&n);
int k=1;
float result;
for(int i=0;i<n;i++)
{
if(i%2==0)
{
result=result+1/k; // function add for first and alternatives i.e for all evens
k=k+2; // incrementing k by to as it is given in fun
}
else
{
result=result-1/k; // else substracion alternative, ie all odd numbers
k=k+2;
}
}
printf("Approximate value of pi is %0.1f ",result);
printf(" Question No 4: ");
float liters,gallons;
while(c!='n')
{
printf(" Enter the number of liters:");
scanf("%f",&liters);
gallons=liters*gpl; // converting literes to gallons
printf(" If Car can deliver 20 miles per gallons");
printf(" car can travell:");
printf("%f miles",funct(gallons)); // calling function to print miles
printf("Enter y to continue n to exit Question No 4"); //
scanf("%c",&c);
}
return 0;
}
float funct(float g)
{
return 20*g;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.