0% found this document useful (0 votes)
30 views1 page

Using Namespace Int Int Char For For For If

This C++ program takes in 10 words from the user, stores them in a 2D character array, then sorts the words in lexicographical (dictionary) order using nested for loops and string comparison/copy functions. It outputs the sorted words.

Uploaded by

Viraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Using Namespace Int Int Char For For For If

This C++ program takes in 10 words from the user, stores them in a 2D character array, then sorts the words in lexicographical (dictionary) order using nested for loops and string comparison/copy functions. It outputs the sorted words.

Uploaded by

Viraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream>

#include <cstring>
using namespace std;
int main(){
int i,j;
char str[10][50],temp[50];
cout << "Enter 10 words: " << endl;
for(i=0;i<10;++i)
cin.getline(str[i], 50);
for(i=0;i<9;++i)
for(j=i+1;j<10 ;++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<10;++i){
cout << str[i] << endl;
}
return 0;
}

You might also like