Program to read display add and subtract the two distances using structures

#include<stdio.h>
#include<conio.h>
struct hi
{
    int k1,k2;
    int m1,m2;
} kil;
main()
{
    int a;
    printf("Enter the first distance in parts of kilometres and metres respectively\n");
    scanf("%d",&kil.k1);
    scanf("%d",&kil.m1);
    printf("Enter the second distance in parts of kilometres and metres respectively\n");
    scanf("%d",&kil.k2);
    scanf("%d",&kil.m2);
    printf("Select the operation\n1. Addition\n2. Subtraction\n3. Read\n4. Display\n5. Exit\n");
    scanf("%d",&a);
    if(a==1)
    {
        printf("Addition - %d Kilometres & %d Metres",kil.k1+kil.k2,kil.m1+kil.m2);
    }
    else if(a==2)
    {
        printf("Subtraction - %d Kilometres & %d Metres)",kil.k1-kil.k2,kil.m1-kil.m2);
    }
    else if(a==3)
    {
        printf("Distances entered by you:\n1. %d Kilometres & %d Metres",kil.k1,kil.m1);
        printf("Distances entered by you:\n2. %d Kilometres & %d Metres",kil.k2,kil.m2);
    }

    else if(a==4)
     {
        printf("Distances entered by you:\n1. %d Kilometres & %d Metres",kil.k1,kil.m1);
        printf("Distances entered by you:\n2. %d Kilometres & %d Metres",kil.k2,kil.m2);
    }
    else if(a==5)
    {
        exit(1);
    }

    else
        {
            printf("Not a valid operation.");

        }

}

 

Output:

14_3

One thought on “Program to read display add and subtract the two distances using structures”

  1. I relish, cause I discovered just what I used to be taking a look for. You’ve ended my 4 day lengthy hunt! God Bless you man. Have a great day. Bye keedackkbdeeaeab

Leave a Reply

Your email address will not be published.