Comparing two names for sort order – CSKC
Sign In

Search

Solved Problem #CPP#2577    siteicon   siteicon  

Problem Statement - Comparing two names for sort order

Write a program using the strcmp() function to prove that the name RAKESH will come before the name RAMESH in an
ascending order sorted list.

Solution

TC++ #2577

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

int sc=strcmp(str1,str2);  //This stores the result of comparison in sc.
if(sc<0)  //This condition is true when first string is alphabetically prior in ascending sort order

cout<<“RAKESH will come before RAMESH”;
else
cout<<“RAMESH will come before RAKESH”;
Since the selection condition comes true so the first line here is printed and thus the required proof is there.

 

Notes

  • Whenever first string is before in sort order, less than 0 value is returned.


Share

Created: 13-Jan-2018 02:24 | Updated: 13-Jan-2018 02:29|