C Online Compiler
Example: C Program to Add Two Distances (in inch-feet) system using Structures
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Add Two Distances (in inch-feet) using Structures #include <stdio.h> // Make structure of the distance struct { int feet; float inches; } x, y, results; // It's the main function of the program int main() { // Step-1 INPUT of the first distance printf("Enter the 1st distance in Feet: "); scanf("%d", &x.feet); printf("Enter the 1st distance in Inches: "); scanf("%f", &x.inches); // Step-2 INPUT of the second distance printf("\nEnter the 2nd distance in Feet: "); scanf("%d", &y.feet); printf("Enter the 2nd distance in Inches: "); scanf("%f", &y.inches); // Step-3 Calculate the values of these distances to make sum results.feet = x.feet + y.feet; results.inches = x.inches + y.inches; // Step-4 It will check the value of the results.inches // If its value is greater or equal to 12 then It will convert and add this value in results.feet while (results.inches >= 12.0) { results.inches = results.inches - 12.0; results.feet++; } // Step-5 Final output of the program printf("\nFinal distances: %d\'-%.1f\"\n", results.feet, results.inches); return 0; }
30 6.6 85 1
Output
Clear
ADVERTISEMENTS