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
#include <iostream>
#include <string>
using namespace std;
int main () {
    char str[40] = "hi world i am here to help you.";
    string unique_character = "";
    for (int i = 97; i <= 122; i++) {
        for (int j = 0; j < 40; j++) {
            if (char(i) == str[j]) {
                unique_character += char(i) - 32;
                unique_character += char(44);
                break;
            }
        }
    }
    cout << "Sorted: " << unique_character;
}
Comments