Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0266134

Browse files
Create Solution.md
1 parent cf145c2 commit 0266134

File tree

1 file changed

+284
-0
lines changed

1 file changed

+284
-0
lines changed
Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
### Questions
2+
1.
3+
4+
5+
6+
## Explanation:
7+
8+
## Time and Space Complexity:
9+
### `Time Complexity`:
10+
11+
### `Space Complexity`:
12+
13+
## Code:
14+
```c
15+
#include <stdio.h>
16+
typedef struct family
17+
{
18+
char name_wife[20];
19+
int numb_child;
20+
char name_child[10][20];
21+
} family;
22+
typedef union details
23+
{
24+
family fam;
25+
char hobby[30];
26+
} details;
27+
typedef struct member
28+
{
29+
char name[20];
30+
int age;
31+
char addr[100];
32+
char active, married;
33+
details det;
34+
} member;
35+
void input(member c[2])
36+
{
37+
for (int i = 0; i < 2; i++)
38+
{
39+
printf("\n\nEnter the name of the member: ");
40+
scanf(" %s", c[i].name);
41+
printf("Enter the age of the person: ");
42+
scanf("%d", &c[i].age);
43+
printf("Enter the address of the person: ");
44+
scanf(" %[^\n]", c[i].addr);
45+
printf("Enter active status (Y/N): ");
46+
scanf(" %c", &c[i].active);
47+
printf("Enter Marital Status (Y/N): ");
48+
scanf(" %c", &c[i].married);
49+
if (c[i].married == 'Y')
50+
{
51+
printf("Enter name of the wife: ");
52+
scanf(" %s", c[i].det.fam.name_wife);
53+
printf("Enter the number of children: ");
54+
scanf("%d", &c[i].det.fam.numb_child);
55+
for (int i = 0; i < c[i].det.fam.numb_child; i++)
56+
{
57+
printf("Enter name of the children: ");
58+
scanf(" %s", c[i].det.fam.name_child[i]);
59+
}
60+
}
61+
else
62+
{
63+
printf("Enter the hobby of the member: ");
64+
scanf(" %[^\n]", c[i].det.hobby);
65+
}
66+
}
67+
}
68+
int main()
69+
{
70+
member c[2];
71+
input(c);
72+
printf("The list of married active players and their wives is as follows:\n");
73+
printf("Name\tWife");
74+
for (int i = 0; i < 2; i++)
75+
{
76+
if (c[i].active == 'Y' && c[i].married == 'Y')
77+
printf("\n%s\t%s\n", c[i].name, c[i].det.fam.name_wife);
78+
}
79+
return 0;
80+
}
81+
```
82+
83+
<hr>
84+
85+
2.
86+
87+
## Explanation:
88+
89+
## Time and Space Complexity:
90+
### `Time Complexity`:
91+
92+
### `Space Complexity`:
93+
94+
## Code:
95+
```c
96+
#include <stdio.h>
97+
#include <string.h>
98+
typedef struct air
99+
{
100+
char src[4];
101+
char des[4];
102+
int start;
103+
int arrival;
104+
int seats;
105+
int count;
106+
} airline_t;
107+
void reset(airline_t c[5])
108+
{
109+
for (int i = 0; i < 5; i++)
110+
c[i].count = 0;
111+
}
112+
void input(airline_t c[5])
113+
{
114+
for (int i = 0; i < 5; i++)
115+
{
116+
printf("\nEnter the source: ");
117+
scanf("%s", c[i].src);
118+
printf("Enter the destination: ");
119+
scanf("%s", c[i].des);
120+
printf("Enter the starting time: ");
121+
scanf("%d", &c[i].start);
122+
printf("Enter the arriving time: ");
123+
scanf("%d", &c[i].arrival);
124+
printf("Enter the number of seats: ");
125+
scanf("%d", &c[i].seats);
126+
c[i].count = 0;
127+
}
128+
}
129+
int main()
130+
{
131+
int d = 1, temp = 0, n, flag = 0, seat;
132+
airline_t c[5];
133+
input(c);
134+
char source[4], dest[4];
135+
do
136+
{
137+
printf("\nEnter your source: ");
138+
scanf("%s", source);
139+
printf("Enter your destination: ");
140+
scanf("%s", dest);
141+
printf("\nStart\tEnd\tSeats\n");
142+
for (int i = 0; i < 5; i++)
143+
{
144+
if (strcmp(c[i].src, source) == 0 && strcmp(c[i].des, dest) == 0 &&
145+
c[i].seats > 0)
146+
{
147+
printf("%d\t%d\t%d\n", c[i].start, c[i].arrival, c[i].seats);
148+
c[i].count = d;
149+
d++;
150+
temp++;
151+
}
152+
}
153+
if (temp == 0)
154+
{
155+
printf("\nSorry we dont have any flights available");
156+
}
157+
else
158+
{
159+
printf("Enter the number of flight you want to take: ");
160+
scanf("%d", &n);
161+
printf("Enter the number of seats you want to book: ");
162+
scanf("%d", &seat);
163+
for (int i = 0; i < 5; i++)
164+
{
165+
if (n == c[i].count)
166+
{
167+
if (c[i].seats - seat >= 0)
168+
{
169+
c[i].seats -= seat;
170+
printf("Your flight has been booked for %s to %s", c[i].src, c[i].des);
171+
printf("\nTimings are follows: %d to %d", c[i].start, c[i].arrival);
172+
printf("\nNo of seats remaining: %d", c[i].seats);
173+
}
174+
else
175+
{
176+
printf("The flight does not have %d seats available", seat);
177+
printf("\nPlease select a different flight.");
178+
}
179+
}
180+
}
181+
}
182+
printf("Enter 0 to continue booking or any other number to exit");
183+
scanf("%d", &flag);
184+
reset(c);
185+
} while (flag == 0);
186+
return 0;
187+
}
188+
```
189+
190+
<hr>
191+
192+
3.
193+
194+
195+
## Explanation:
196+
197+
## Time and Space Complexity:
198+
### `Time Complexity`:
199+
200+
### `Space Complexity`:
201+
202+
## Code:
203+
```c
204+
#include <stdio.h>
205+
#include <string.h>
206+
typedef struct employee
207+
{
208+
char name[20];
209+
char gender;
210+
int salary;
211+
int day;
212+
int month;
213+
int year;
214+
int age;
215+
} employee;
216+
int main()
217+
{
218+
employee c[10];
219+
int i;
220+
char name[5][20];
221+
for (i = 0; i < 5; i++)
222+
{
223+
printf("Enter the name: ");
224+
scanf(" %s", c[i].name);
225+
printf("Enter the gender (M/F): ");
226+
scanf(" %c", &c[i].gender);
227+
printf("Enter the salary: ");
228+
scanf("%d", &c[i].salary);
229+
printf("Enter the Date of Birth (DD MM YYYY): ");
230+
scanf("%d %d %d", &c[i].day, &c[i].month, &c[i].year);
231+
c[i].age = 2022 - c[i].year;
232+
printf("\n");
233+
}
234+
printf("Amendments: ");
235+
for (int k = 0; k < 5; k++)
236+
{
237+
int flag = 0;
238+
printf("\nEnter the name: ");
239+
scanf(" %s", name[k]);
240+
for (int j = 0; j < 10; j++)
241+
{
242+
if (strcmp(c[j].name, name[k]) == 0)
243+
{
244+
int choice;
245+
printf("Enter 1 if employee has left and 2 if employee if the
246+
salary is to be modified: ");
247+
scanf("%d",&choice);
248+
if(choice == 1)
249+
c[j].salary = 0;
250+
else if(choice == 2)
251+
{
252+
printf("Enter the new salary: ");
253+
scanf("%d", &c[j].salary);
254+
}
255+
flag = 1;
256+
break;
257+
}
258+
}
259+
if (flag == 0)
260+
{
261+
strcpy(c[i].name, name[k]);
262+
printf("Enter the gender of the employee (M/F): ");
263+
scanf(" %c", &c[i].gender);
264+
printf("Enter the salary of the employee: ");
265+
scanf("%d", &c[i].salary);
266+
printf("Enter the date of birth (DD MM YYYY) : ");
267+
scanf("%d %d %d", &c[i].day, &c[i].month, &c[i].year);
268+
c[i].age = 2022 - c[i].year;
269+
i++;
270+
}
271+
}
272+
printf("Name\tGender\tSalary\tDate of Birth");
273+
for (int k = 0; k < i; k++)
274+
{
275+
if (c[k].age < 60 && c[k].salary != 0)
276+
printf("\n%s\t%c\t%d\t%d %d
277+
%d",c[k].name,c[k].gender,c[k].salary,c[k].day,c[k].month,c[k].year);
278+
}
279+
return 0;
280+
}
281+
```
282+
283+
<hr>
284+

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /