Q:

Write a C Program to add two distances in inch-feet system using Structure

0

Write a C Program to add two distances in inch-feet system using Structure

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
struct Distance
{
    int feet;
    float inch;
}
 
d1, d2, sum_of_Distances;
 
int main()
{
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    scanf("%d", &d1.feet);
    printf("Enter inch: ");
    scanf("%f", &d1.inch);
 
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    scanf("%d", &d2.feet);
    printf("Enter inch: ");
    scanf("%f", &d2.inch);
 
 
    sum_of_Distances.feet = d1.feet+d2.feet;
    sum_of_Distances.inch = d1.inch+d2.inch;
 
 
    if (sum_of_Distances.inch>12.0)
    {
        sum_of_Distances.inch = sum_of_Distances.inch-12.0;
        ++sum_of_Distances.feet;
    }
 
    printf("\nSum of distances = %d\'-%.1f"",sum_of_Distances.feet, sum_of_Distances.inch);
    return 0;
}

Result:

Enter information for 1st distance

Enter feet: 5

Enter inch: 12

Enter information for 2nd distance

Enter feet: 6

Enter inch: 5

Sum of distances = 12'-5.0"

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now