assignment-s-22.c (873B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 18 Jan 2026 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a program using structures to add two distances in meter-kilometer format. */ 8 9 #include <stdio.h> 10 #include <stdlib.h> 11 12 struct distance 13 { 14 int km; 15 int m; 16 }; 17 18 void total_distance(struct distance[]); 19 20 int main() 21 { 22 struct distance dis[2] = {0}; 23 printf("Enter the 1st distance (KM M): "); 24 scanf("%d %d", &dis[0].km, &dis[0].m); 25 printf("Enter the 2nd distance: "); 26 scanf("%d %d", &dis[1].km, &dis[1].m); 27 total_distance(dis); 28 return 0; 29 } 30 31 void total_distance(struct distance dis[]) 32 { 33 int result_km = dis[0].km + dis[1].km; 34 int result_m = dis[0].m + dis[1].m; 35 result_km += result_m / 1000; 36 result_m = result_m % 1000; 37 printf("Total distance: %d KM, %d M", result_km, result_m); 38 }