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


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

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


  1. #include <stdio.h>
  2.  
  3. struct Distance
  4. {
  5. int feet;
  6. float inch;
  7. }
  8.  
  9. d1, d2, sum_of_Distances;
  10.  
  11. int main()
  12. {
  13. printf("Enter information for 1st distance\n");
  14. printf("Enter feet: ");
  15. scanf("%d", &d1.feet);
  16. printf("Enter inch: ");
  17. scanf("%f", &d1.inch);
  18.  
  19. printf("\nEnter information for 2nd distance\n");
  20. printf("Enter feet: ");
  21. scanf("%d", &d2.feet);
  22. printf("Enter inch: ");
  23. scanf("%f", &d2.inch);
  24.  
  25.  
  26. sum_of_Distances.feet = d1.feet+d2.feet;
  27. sum_of_Distances.inch = d1.inch+d2.inch;
  28.  
  29.  
  30. if (sum_of_Distances.inch>12.0)
  31. {
  32. sum_of_Distances.inch = sum_of_Distances.inch-12.0;
  33. ++sum_of_Distances.feet;
  34. }
  35.  
  36. printf("\nSum of distances = %d\'-%.1f\"",sum_of_Distances.feet, sum_of_Distances.inch);
  37. return 0;
  38. }
  39.  

Result

C language techstudy.org

     





Related Topics




Popular Posts