Program to to calculate distance b/w two heights passing structure as pointers to the function

#include<stdio.h>
struct height1
{
    int a,b
} h1;
//int func(struct height1 *h1);
main()
{
    int diff;
    printf("Enter the two heights to get the difference b/w them.\n");
    scanf("%d",&h1.a);
    scanf("%d",&h1.b);

    diff = height(&h1);

}
int height(struct height1 *h1)
{
    if((*h1).a > (*h1).b)
    {

    printf("Difference of heights is %d",(*h1).a-(*h1).b);
    }
    else if((*h1).b > (*h1).a)
    {
         printf("Difference of heights is %d",(*h1).b-(*h1).a);
    }
    else if((*h1).a==(*h1).b)
    {
        printf("Difference of heights is 0");
    }

}

21_2

Leave a Reply

Your email address will not be published.