-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path17.c
More file actions
51 lines (46 loc) · 1022 Bytes
/
Copy path17.c
File metadata and controls
51 lines (46 loc) · 1022 Bytes
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
49
50
51
// Write a C program to find the largest and smallest sized word in a string.
#include <stdio.h>
int main()
{
char str[100];
printf("Enter the string: ");
scanf("%[^\n]%*c", str);
int i = 0;
int min = 100, max = 0;
int min_index = 0, max_index = 0;
while (str[i] != '\0')
{
int count = 0;
while (str[i] != ' ' && str[i] != '\0')
{
count++;
i++;
}
if (count < min)
{
min = count;
min_index = i - count;
}
if (count > max)
{
max = count;
max_index = i - count;
}
if (str[i] == '\0')
{
break;
}
i++;
}
printf("The smallest word is: ");
for (int j = min_index; j < min_index + min; j++)
{
printf("%c", str[j]);
}
printf("\n");
printf("The largest word is: ");
for (int j = max_index; j < max_index + max; j++)
{
printf("%c", str[j]);
}
}