-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path05_largest_string.cpp
51 lines (40 loc) · 1014 Bytes
/
05_largest_string.cpp
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
/*
Largest String
- Read N, followed by N strings and print the largest string and its length
*/
#include <iostream>
#include <cstring>
using namespace std;
int main(){
int totalStr;
cout << "Enter total number of Strings: ";
cin >> totalStr;
cin.get(); // to consume extra "\n"
char currString[1000];
char maxString[1000];
int currLen = 0;
int maxLen = 0;
cout << "Enter your strings: \n;";
for(int itr=0; itr<=totalStr-1; itr++){
cin.getline(currString, 1000);
currLen = strlen(currString);
if(currLen > maxLen){
maxLen = currLen;
strcpy(maxString,currString);
}
}
cout << "\nMaximum String: " << maxString << "\nlength - " << maxLen << endl;
return 0;
}
/*
OUTPUT:
Enter total number of Strings: 5
Enter your strings:
raman deep
amarjeet singh
ravinder sharma
mandeep sharma
ravi juneja
Maximum String: ravinder sharma
length - 15
*/