C Program to Add Two Distance Given as Input in Feet and Inches

Using this article, You can execute the program of “C Program to Add Two Distance Given as Input in Feet and Inches” successfully without facing any troubles. Let’s start the execution process using this article below.

C Program to Add Two Distance Given as Input in Feet and Inches

C Program to Add Two Distance Given as Input in Feet and Inches

Program Code

#include <stdio.h>
struct distance{
    int feets;
    int inchs;
};

void addDistance(struct distance firstdistance,struct distance seconddistance){
    struct distance totalsum;
    totalsum.feets= firstdistance.feets + seconddistance.feets;
    totalsum.inchs= firstdistance.inchs + seconddistance.inchs;
    
    totalsum.feets= totalsum.feets + totalsum.inchs/12; //1 feet has 12 inches
    totalsum.inchs= totalsum.inchs%12;
    
    printf("nTotal Distance is: %d Feets, and %d' Inches",totalsum.feets,totalsum.inchs);
}

int main()
{
    
    /*C Program to Add Two Distance Given as Input in Feet and Inches. distances*/
    
    struct distance firstdistance,seconddistance;
    
    printf("Enter the First Distance in Feets: ");
    scanf("%d",&firstdistance.feets);
    printf("Enter First Distance in Inches: ");
    scanf("%d",&firstdistance.inchs);    
    
    printf("nnEnter Second Distance in Feets: ");
    scanf("%d",&seconddistance.feets);
    printf("Enter Second Distance in Inches: ");
    scanf("%d",&seconddistance.inchs); 

    addDistance(firstdistance,seconddistance);
    return 0;
}

Final Words

I hope this article helps you to understand about “C Program to Add Two Distance Given as Input in Feet and Inches“. If you face any issues please let me know via the comment section. Share this article with other C/C++ program developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment