In: Computer Science
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places
C LANGUAGE
SOURCE CODE:
#include <stdio.h>
int main()
{
float mass,density,volume;
printf("Enter mass in grams:");
//reaeding mass in grams
scanf("%f",&mass);
printf("Enter density in cubic centimeters:");
//reading denstiy in cubic centimeters
scanf("%f",&density);
while(density==0) //density 0 the volume not
defined
{
printf("Please reenter density in
cubic centimeters:");
scanf("%f",&density);
}
// ca;lculating volume
volume=mass/density;
printf("Voume of the object =%.2f",volume);
}
CODE
SCREENSHOT:
OUTPUT:
RUN1;
RUN2;