text: C / C ++ program to add N distances given in inch | C program for the above approach ; Struct defined for the inch - feet system ; Variable to store the inch - feet ; Function to find the sum of all N set of Inch Feet distances ; Variable to store sum ; Traverse the InchFeet array ; Find the total sum of feet and inch ; If inch sum is greater than 11 convert it into feet as 1 feet = 12 inch ; Find integral part of inch_sum ; Delete the integral part x ; Add x % 12 to inch_sum ; Add x / 12 to feet_sum ; Print the corresponding sum of feet_sum and inch_sum ; Driver Code ; Given set of inch - feet ; Function Call
code: #include " stdio . h " NEW_LINE struct InchFeet { int feet ; float inch ; } ; void findSum ( struct InchFeet arr [ ] , int N ) { int feet_sum = 0 ; float inch_sum = 0.0 ; int x ; for ( int i = 0 ; i < N ; i ++ ) { feet_sum += arr [ i ] . feet ; inch_sum += arr [ i ] . inch ; } if ( inch_sum >= 12 ) { x = ( int ) inch_sum ; inch_sum -= x ; inch_sum += x % 12 ; feet_sum += x / 12 ; } printf ( " Feet ▁ Sum : ▁ % d STRNEWLINE " , feet_sum ) ; printf ( " Inch ▁ Sum : ▁ % .2f " , inch_sum ) ; } int main ( ) { struct InchFeet arr [ ] = { { 10 , 3.7 } , { 10 , 5.5 } , { 6 , 8.0 } } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findSum ( arr , N ) ; return 0 ; }