VOOZH about

URL: https://www.geeksforgeeks.org/c/menu-driven-program-to-convert-mks-to-cgs-and-cgs-to-mks/

⇱ Menu Driven Program to convert MKS to CGS and CGS to MKS - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Menu Driven Program to convert MKS to CGS and CGS to MKS

Last Updated : 12 Jul, 2025

Prerequisite: Switch Case in C/C++
Problem Statement: 
Write a menu-driven program using the Switch case to convert the CGS system to MKS system and vice versa.
Approach: 
The MKS System of units refers to the physical measurement system in which the Dimensions length, weight and time are measured in Meters, Kilograms and Seconds respectively.
 

MKS System:

Length - meters (m)
Weight - kilograms (kg)
Time - seconds (s)


The CGS System of units refers to the physical measurement system in which the Dimensions length, weight and time are measured in Centimeters, Grams and Seconds respectively.
 

CGS System:

Length - centimeters (cm)
Weight - grams (g)
Time - seconds (s)


 
In order to convert the MKS system to the CGS system, the conversion is done as follows:
 

For Length:
Since, 
 1 meter = 100 centimeter
Therefore, 
 multiply the given length value by 100.

For Weight:
Since, 
 1 kilogram = 1000 gram
Therefore, 
 multiply the given weight value by 1000.

For Time:
Since, 
 1 second = 1 second
Therefore, 
 The time value will remain the same.


 
Inorder to convert the CGS system to MKS system, the conversion is done as follows:
 

For Length:
Since, 
 1 centimeter = 1/100 met
Therefore, 
 divide the given length value by 100.

For Weight:
Since, 
 1 gram = 1/1000 kilogram
Therefore, 
 divide the given weight value by 1000.

For Time:
Since, 
 1 second = 1 second
Therefore, 
 The time value will remain the same.


Below is the implementation of the above approach:
Program: 
 


Output
Check for CGS to MKS of all units.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 1

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 0

Enter values for distance unit in centimeter.

Enter values for weight unit in grams.

Enter values for time unit in seconds.

The entered values in CGS system are: 
30 300 3000
Corresponding values in MKS system: 
0.3 0.3 3000

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------

Check for CGS to MKS of only distance unit.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 1

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 1

Enter values for distance unit in centimeter.

The entered values in CGS system are: 
30 0 0
Corresponding values in MKS system: 
0.3 0 0

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------

Check for CGS to MKS of only weight unit.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 1

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 2

Enter values for weight unit in grams.

The entered values in CGS system are: 
0 300 0
Corresponding values in MKS system: 
0 0.3 0

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------

Check for CGS to MKS of only time unit.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 1

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 3

Enter values for time unit in seconds.

The entered values in CGS system are: 
0 0 3000
Corresponding values in MKS system: 
0 0 3000

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------
Check for MKS to CGS of all units.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 2

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 0

Enter values for distance unit in meter.

Enter values for weight unit in kilogram.

Enter values for time unit in second.

The entered values in MKS system are: 
30 300 3000
Corresponding values in CGS system: 
3000 300000 3000

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------

Check for MKS to CGS of only distance unit.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 2

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 1

Enter values for distance unit in meter.

The entered values in MKS system are: 
30 0 0
Corresponding values in CGS system: 
3000 0 0

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------

Check for MKS to CGS of only weight unit.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 2

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 2

Enter values for weight unit in kilogram.

The entered values in MKS system are: 
0 300 0
Corresponding values in CGS system: 
0 300000 0

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------

Check for MKS to CGS of only time unit.

MKS <-> CGS converter menu:
Enter 1 for CGS to MKS conversion.
Enter 2 for MKS to CGS conversion.

You have chosen: 2

Enter 0 to convert all three parameters- distance, weight and time.
Enter 1 for converting distance
Enter 2 for converting weight
Enter 3 for converting time

You have chosen: 3

Enter values for time unit in second.

The entered values in MKS system are: 
0 0 3000
Corresponding values in CGS system: 
0 0 3000

Enter 1 to continue, or
Press any other key to exit.

-------------------------------------------------
Comment
Article Tags: