bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / assignment-secondary / assignment-s-22.c

assignment-s-22.c (737B)


      1 /*  Write a program using structures to add two distances in meter-kilometer format. */
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 struct distance
      7 {
      8     int km;
      9     int m;
     10 };
     11 
     12 void total_distance(struct distance[]);
     13 
     14 int main()
     15 {
     16     struct distance dis[2] = {0};
     17     printf("Enter the 1st distance (KM M): ");
     18     scanf("%d %d", &dis[0].km, &dis[0].m);
     19     printf("Enter the 2nd distance: ");
     20     scanf("%d %d", &dis[1].km, &dis[1].m);
     21     total_distance(dis);
     22     return 0;
     23 }
     24 
     25 void total_distance(struct distance dis[])
     26 {
     27     int result_km = dis[0].km + dis[1].km;
     28     int result_m = dis[0].m + dis[1].m;
     29     result_km += result_m / 1000;
     30     result_m = result_m % 1000;
     31     printf("Total distance: %d KM, %d M", result_km, result_m);
     32 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror