fastread homefastrread library fastread menu

C : Add Two Distances (in inch-feet) System Using Structures

Tutorial by:Manisha Dubey      Date: 2016-06-17 04:39:30

❰ Previous Next ❱

This program takes two distances in inch-feet system and stores in data members of two structure variables. Then, this program calculates the sum of two distances and displays it.

Source code to add two distance using structure

#include <stdio.h>
struct Distance{
    int feet;
    float inch;
int main(){
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    printf("Enter inch: ");
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    printf("Enter inch: ");

/* If inch is greater than 12, changing it to feet. */
    if (sum.inch>12.0)
    printf("\nSum of distances=%d\'-%.1f\"",sum.feet,sum.inch);
    return 0;


Enter information for 1st distance
Enter feet: 12
Enter inch: 3.45

Enter information for 1st distance
Enter feet: 12
Enter inch: 9.2

Sum of distances=25'-0.6"


In this program, a structure Distance is defined with inch and feet as its members. Then, three variables(d1, d2 and sum) of struct Distance type is created. Two variables(d1 and d2) are used for taking distance from user and the sum of two distance is stored in variable sum and then, displayed.

❰ Previous Next ❱


Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website