(Comparing Strings) Write a program that uses function strcmp to compare two strings in- put by the user. The program should state whether the first string is less than, equal to or greater than the second string.

What will be an ideal response?


```
#include
#include
using namespace std;

const int SIZE = 20;

int main()
{
char string1[ SIZE ];
char string2[ SIZE ];
int result;

cout << "Enter two strings: ";
cin >> string1 >> string2;

// uses function strcmp to compare the two strings
result = strcmp( string1, string2 );

if ( result > 0 )
cout << '\"' << string1 << '\"' << " is greater than \""
<< string2 << '\"' << endl;
else if ( result == 0 )
cout << '\"' << string1 << '\"' << " is equal to \"" << string2
<< '\"' << endl;
else
cout << '\"' << string1 << '\"' << " is less than \"" << string2
<< '\"' << endl;

return 0; // indicates successful termination
} // end main
```
Enter two strings: green leaf
"green" is less than "leaf"

Computer Science & Information Technology

You might also like to view...

What is the first practical step of the ICT procurement process?

A. Creation of an RFP B. Establishment of a contract C. Creation of requirements D. Creation of a documented justification

Computer Science & Information Technology

What is Inline-block?

What will be an ideal response?

Computer Science & Information Technology

________ is a view optimized for onscreen viewing of reports

A) Design view B) Layout view C) Report view D) Print Preview

Computer Science & Information Technology

The adjacency list uses a two-dimensional ____ array to store the edges.

A. ragged B. sorted C. dynamic D. hash-based

Computer Science & Information Technology