C program to calculate sum of two distances measured in feet and inch using function:

program to calculate sum of two distances measured in feet and inch using function:

#include stdio.h
void sum(struct distance d1,struct distance d2);
struct distance
{
    int feet;
    int inch;
};
void main()
{
    struct distance d1,d2;
    printf("\n Enter the first distance in feet inch format:");
    scanf("%d%d",&d1.feet,&d1.inch);
    printf("\n Enter the second distance in feet and inch format:");
    scanf("%d%d",&d2.feet,&d2.inch);
    sum(d1,d2);
}
void sum(struct distance d1,struct distance d2)
{
    struct distance d;
    d.inch=(d1.inch+d2.inch)%12;
    d.feet=d1.feet+d2.feet+(d1.inch+d2.inch)/12;
    printf("\n sum of two distances = %dFeet %dInch",d.feet,d.inch);
}

Comments

Popular posts from this blog

How to prepare a mark sheet in ms word?

Logical Diagram Of Computer