Pages

Thursday, 28 September 2017

Metric Conversion with structure

Q :Define two structures Metric and British that store distances. The Metric stores values in meters and centimeters and the British stores values in feet and inches. Write a program that reads both structure variables and add values contained in one variable of Metric to the contents of another variable of British. The program should display the result in both: equivalent centimeters and equivalent inches.


Solution : 



For solve this question you need to know metric measurement unit.

1 centimeter = 10 millimeters
1 meter = 100 centimeters = 1,000 millimeters

1 kilometer = 1,000 meters = 100,000 centimeters = 100,000,000 millimeters = 1*108 millimeters

1 inch = 2.54 centimeters = 25.4 millimeters
1 foot = 30.48 centimeters
1 yard = 0.91 meters
1 mile = 1.6 kilometers

1 millimeter = 0.04 inches
1 centimeter = .39 inches = 0.0325 feet
1 meter = 3.28 feet

1 kilometer = 0.62 miles

#include<stdio.h>
struct Metric
{
     float meter,centimeter;
};
struct British
{
     float feet,inch;
};
void main()
{
     struct Metric M;
     struct British B;
     float centimeter,inch;
     int i;
     printf("Enter Meter and Centimeter>> ");
     scanf("%f%f",&M.meter,&M.centimeter);
     printf("Enter Feet and Inch>> ");
     scanf("%f%f",&B.feet,&B.inch);
     inch=(M.meter*100/2.54f)+(M.centimeter/2.54f)+(B.feet*30.48f/2.54f)+(B.inch);
     i=inch;
     centimeter=(inch-i)*2.54f;
     printf("\nInch=%f\nCentimeter=%f",inch,centimeter);
}



2 comments: