Computer Science, asked by ketwanfelix, 1 year ago

Write a program that inputs the length of two pieces of fabric in feet and inches (as whole numbers) and prints the total. In C

Answers

Answered by sushiladevi4418
1

Answer:

Write a program that inputs the length of two pieces of fabric in feet and inches (as whole numbers) and prints the total in C programming.

Explanation:

#include <stdio.h>

int main (void) {  

unsigned f1, i1, f2, i2;  

scanf ("Enter the 1st length in feet and inches: %u%u", f1, i1);  

scanf ("Enter the 2nd length in feet and inches: %u%u", f2, i2);  

unsigned inches = i1 + i2 + (12 * (f1 + f2)); // sum the inches (convert feet to inches)

unsigned feet = inches / 12; // convert inches to feet  

inches %= 12; // determine the remaining inches  

printf ("The total length is %u feet %u inches.\n", feet, inches);  

return 0;  

}

Similar questions