A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) Using For Loop
Q:

C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) Using For Loop

0

Write C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) Using For Loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
#include <cstring>
using namespace std;
int main()
{
    int i,j,n;
    char str[10][50],temp[50];
 
    cout << "Enter The No. Of Words: " << endl;
    cin>>n;
    for(i=0;i<n;++i)
        cin.getline(str[i], 50);
     
    for(i=0;i<n-1;++i)
       for(j=i+1;j<n ;++j)
    {
          if(strcmp(str[i],str[j])>0)
          {
            strcpy(temp,str[i]);
            strcpy(str[i],str[j]);
            strcpy(str[j],temp);
          }
    }
    cout << "In lexicographical order: " << endl;
    for(i=0;i<n;++i){
       cout << str[i] << endl;
    }
return 0;
}

 

Output:

Enter The No. Of Words: 

10

nerdutella

example

c++

programming

mcv

love

niit t

month

year

In lexicographical order: 

c++

example

love

mcv

month

nerdutella

nit

programming

year

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now