Answer to Question #157833 in C++ for ayesha

Question #157833

Question # 1

Initialize a string of size 40. Write a program that prints all unique alphabets from string. After printing them sort them in ascending order.

For example: Hi world I am here to help you.

Unique characters are: H, I, W, O, R, L, D, A, M, E, T, P, Y, U.

Sorted: A, D, E, H, I , L,M, O, P, R, T, U, W, Y


1
Expert's answer
2021-01-23T15:46:09-0500
#include<bits/stdc++.h>
using namespace std;
#define MAX 100
 
void sortStrings(char arr[][MAX], int n)
{
    char temp[MAX];
 
    // Sorting strings using bubble sort
    for (int j=0; j<n-1; j++)
    {
        for (int i=j+1; i<n; i++)
        {
            if (strcmp(arr[j], arr[i]) > 0)
            {
                strcpy(temp, arr[j]);
                strcpy(arr[j], arr[i]);
                strcpy(arr[i], temp);
            }
        }
    }
    cout<<arr<<endl;
}
int main(){
    
     char arr[40] = "GeeksforGeeks";
    
     int n = sizeof(arr)/sizeof(arr[0]);
     for (int i=0; i<n; i++)
        cout<<arr[i];
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog