Add two lengths

Description

Get two lengths in feet and inches and add them
Input:
6:03
4:11
Output:
11:02

Solution

#include<stdio.h>
struct length{
	int feet;
	int inch;
};

int main()
{
	struct length l1,l2,l3;
	printf("Enter First Length:");
	scanf("%d:%d",&l1.feet,&l1.inch);
	printf("Enter second Length:");
	scanf("%d:%d",&l2.feet,&l2.inch);
	l3.inch=l1.inch+l2.inch;
	l3.feet=l1.feet+l2.feet;
	if(l3.inch>11)
	{
		l3.feet++;
		l3.inch=l3.inch-12;
	}
	printf("%d:%d",l3.feet,l3.inch);
	return 0;
}

Explanation

l1,l2 and l3 are structure varibles, each occupies 8btyes. 4 bytes for feet and 4bytes for feet.

Add inches of l1 and l2 and store it in l3, then add feets of l1 and l2 and store it in l3.
if l3 inches is greater than 11 then increment l3 feet by and decrement l3 inch by 12.
Ramesh P Natarajan

Author - Ramesh P Natarajan

Learner, Professor, Technology Trainer, Software Developer and Content Marketer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: admin@decodeschool.com





Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution