luc080.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 08 Feb 2026
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Automobile engine parts (Serial AA0-FF9, Year, Material, Qty). Retrieve parts between serial numbers BB1 and CC6.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct part
{
char serial[4]; // 3 chars + null terminator
int mfg_year;
char material[20];
int quantity;
};
void retrieve_parts(struct part *p, int n);
int main()
{
struct part inventory[] = {
{"AA0", 2020, "Steel", 50},
{"BB2", 2021, "Aluminum", 20},
{"BB5", 2022, "Carbon", 10},
{"CC1", 2021, "Steel", 100},
{"CC7", 2023, "Titanium", 5},
{"FF9", 2024, "Iron", 60}
};
int n = 6;
printf("--- Parts with Serial Numbers between BB1 and CC6 ---\n");
retrieve_parts(inventory, n);
return 0;
}
void retrieve_parts(struct part *p, int n)
{
int i;
// We compare strings lexicographically
char start[] = "BB1";
char end[] = "CC6";
for (i = 0; i < n; i++)
{
if (strcmp(p[i].serial, start) >= 0 && strcmp(p[i].serial, end) <= 0)
{
printf("Serial: %s | Year: %d | Mat: %s | Qty: %d\n",
p[i].serial, p[i].mfg_year, p[i].material, p[i].quantity);
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48