Calculating Force, Mass and Acceleration using functions in C || Type 2 || Functions || C programming
In this program, we are going to see how to Calculate Force, Mass and Acceleration (Type-2) in C Programming Language.

 

#include <stdio.h>
#include <stdlib.h>

void Force(float mass, float acceleration)
{
    float force;

    force = mass * acceleration;

    printf("The Force is : %.2f N", force);
}

void Mass(float force, float acceleration)
{
    float mass;
    mass = force / acceleration;

    printf("The Mass is : %.2f Kg", mass);
}

void Acceleration(float force, float mass)
{
    float acceleration;

    acceleration = force / mass;

    printf("The Acceleration is : %.2f m/s^2", acceleration);
}

void main()
{
    int operation;
    float f, m, a;
    printf("-----Select the Operation------\n");
    printf("1. Calculate Force\n2. Calculate Mass\n3. Calculate Acceleration\n4. Exit\n");
    printf("Enter the corresponding number of Operation: ");
    scanf("%d", &operation);

    switch (operation)
    {
    case 1:
        printf("Enter the Mass: ");
        scanf("%f", &m);
        printf("Enter the Acceleration: ");
        scanf("%f", &a);
        Force(m, a);
        break;

    case 2:
        printf("Enter the Force: ");
        scanf("%f", &f);
        printf("Enter the Acceleration: ");
        scanf("%f", &a);
        Mass(f, a);
        break;

    case 3:
        printf("Enter the Force: ");
        scanf("%f", &f);
        printf("Enter the Mass: ");
        scanf("%f", &m);
        Acceleration(f, m);
        break;

    case 4:
        exit(0);
        break;

    default:
        printf("Wrong input");
    }
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post