C Program to Check Weight On Other Planets

Introduction

In this post, I am going to write a c program to check weight on other planets. That means this program will ask the user to enter his weight on the earth. Next, he will be asked to enter the planet name on which he wants to check his respective weight.

Also Read: Switch Case in C Program to Calculate Area of Circle and Triangle

What is Weight of a body?

The weight of a body is the force of gravity exerted by the planet on it. The gravity of the earth is 9.8 m/s2. Suppose, if your weight on earth is 50 Kg, then it is because of the gravity of the earth. If you change the planet then your weight will also be changed because gravity is changing.

Different planets have different gravities. For example, gravity on mars is 3.721 m/s2. Following are the formulae to calculate the weight of the body on the other planets.

Formula to check weight on other planet

 Weight on planet P = ( Weight on Earth / 9.81 ) * Gravity on planet P

I will use the above formula in this program.

For example,

1. Weight on Mars = ( Weight on Earth / 9.81 )* 3.721
2. Weight on Venus = ( Weight on Earth / 9.81 )* 8.87
3. Weight on Mercury = ( Weight on Earth / 9.81 )* 3.7
4. Weight on Saturn = ( Weight on Earth / 9.81 )* 10.44
5. Weight on Moon = ( Weight on Earth / 9.81 )* 1.622

Here, this program will find only the weight for the 5 different planets which are given above. You can use the same formula to calculate weight with the different planets which is not given above. You just need to know the gravity of that planet.

Also Read: C Program to Remove Zeros from a number

Expected Output

C Program to Check Weight On Other Planets
Fig. C Program to Check Weight On Other Planets

As you can see from the above output, we are asking the user to enter his current age in kg. After that, we will give him a choice to choose the planet. If he selects any planet from the given list, then his current weight on that planet will be displayed on the screen.

Also Read: C Program to Print Multiples of 5 using do-while loop

In this program, I have used a switch case statement. If you want to add more planets, then you will simply need to add the number of cases and use the respective formula. Now, it is time to see the actual c program to check the weight on other planets.

C Program to Check Weight On Other Planets

#include <stdio.h>
#include <stdlib.h>
#define EARTH 9.81
#define MARS 3.721
#define VENUS 8.87
#define MERCURY 3.7
#define SATURN 10.44
#define MOON 1.622
int main()
{
    int e_weight,choice;
    float p_weight;
    printf("Enter your weight on the Earth in Kg\n");
    scanf("%d",&e_weight);
    printf("List of Planets\n");
    printf("1. Mars\n");
    printf("2. Venus\n");
    printf("3. Mercury\n");
    printf("4. Saturn\n");
    printf("5. Moon\n");
    printf("Select your Choice: ");
    scanf("%d",&choice);
    printf("Weight on the Earth: %d Kg",e_weight);
    switch(choice)
    {
    case 1:
        p_weight=(e_weight/EARTH)*MARS;
        printf("\nWeight on the Mars: %0.2f Kg",p_weight);
        break;
    case 2:
        p_weight=(e_weight/EARTH)*VENUS;
        printf("\nWeight on the Venus: %0.2f Kg",p_weight);
        break;
    case 3:
        p_weight=(e_weight/EARTH)*MERCURY;
        printf("\nWeight on the Mercury: %0.2f Kg",p_weight);
        break;
    case 4:
        p_weight=(e_weight/EARTH)*SATURN;
        printf("\nWeight on the Saturn: %0.2f Kg",p_weight);
        break;
    case 5:
        p_weight=(e_weight/EARTH)*MOON;
        printf("\nWeight on the Moon: %0.2f Kg",p_weight);
        break;
    default:
        printf("\nInvalid Choice");
    }
    return 0;
}

Here, e_weight is the weight of the user on the earth and w_weight is the weight on the other planets.

I hope, you have understood the above program. If you have any difficulty regarding the above program, then please feel free to contact me.

Thank you.

Some Important C Programs

  1. The while loop in C Programming
  2. Reverse a Number using getchar and putchar function in c
  3. C Program to Print Numbers Except Multiples of n
  4. C Program to Remove White Spaces and Comments from a File
  5. Program in C to Find Longest Line in a File
  6. Palindrome in C using Pointers
  7. Insert and Delete element in Array in C using switch case
  8. C Program to Add Alternate Elements of a 2D Array
  9. Arrays in C for Complete Beginners
  10. C Program to Find Area of a Circle using Preprocessor

Leave a Comment