-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexi.c
47 lines (35 loc) · 1.24 KB
/
lexi.c
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
#include <stdio.h>
#include <string.h>
int main() {
char str[5][50], temp[50];
printf("Enter 5 words: ");
// Getting strings input
for (int i = 0; i < 5; ++i) {
fgets(str[i], sizeof(str[i]), stdin);
}
// storing strings in the lexicographical order
for (int i = 0; i < 5; ++i) {
for (int j = i + 1; j < 5; ++j) {
// swapping strings if they are not in the lexicographical order
if (strcmp(str[i], str[j]) > 0) {
strcpy(temp, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], temp);
}
}
}
printf("\nIn the lexicographical order: \n");
for (int i = 0; i < 5; ++i) {
fputs(str[i], stdout);
}
return 0;
}
/*
👋 Hi, I’m @aarushinair - Aarushi Nair (she/her/ella)
👀 I’m a Computer Science Engineering Student
💞️ I’m looking to collaborate on #java, #python, #R, #applicationdevelopment
🌱 #GirlsWhoCode #WomenInTech #WomenInIT #WomenInSTEM #CyberSecurity #QuantumComputing #BlockChain #AI #ML
📫 How to reach me: https://www.linkedin.com/in/aarushinair/
👩🏫 YouTube Channel - Code with Aarushi : https://www.youtube.com/channel/UCKj5T1ELHCmkGKujkpqtl7Q
🙋 Follow me on Twitter: https://twitter.com/aarushinair_
*/