Add two distances in inch-feet system using Structure

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


Source Code:

#include<stdio.h>
#include<conio.h>
struct inch_feet_demo
{
	int feet1,inch1,feet2,inch2;
};
void main()
{
	struct inch_feet_demo s1;
	int inch_ans,feet_ans;
	clrscr();
	printf("Enter the Feet-1:");
	scanf("%d",&s1.feet1);
	printf("Enter the Inch-1:");
	scanf("%d",&s1.inch1);
	printf("Enter the Feet-2:");
	scanf("%d",&s1.feet2);
	printf("Enter the Inch-2:");
	scanf("%d",&s1.inch2);

	feet_ans=s1.feet1+s1.feet2;
	inch_ans=s1.inch1+s1.inch2;

	if(inch_ans>12)
	{
		feet_ans++;
		inch_ans=inch_ans-12;
	}

	printf("Total Feet:%d \n",feet_ans);
	printf("Total Inch:%d \n",inch_ans);
	getch();
}

Output:

Enter the Feet-1: 2
Enter the Inch-1: 9
Enter the Feet-2: 5
Enter the Inch-2: 10

Total Feet: 8
Total Inch: 7

Leave a Reply

Your email address will not be published. Required fields are marked *