Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- int read(char array[]){
- int count = 0;
- cin >> array;
- return strlen(array);
- }
- void sort(char array[], int size){
- for (int i = 0; i<size; i++){
- for (int j = i + 1; j<size; j++){
- if (array[i] > array[j]){
- char temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- }
- }
- }
- void print(char array[], int size){
- for (int i = 0; i<size; i++)
- cout << array[i];
- cout << endl;
- }
- int main(){
- const int SIZE = 80;
- char array[SIZE];
- int sizeIn, sizeDet;
- cout<<"Read in a 1 dimensional array of characters and sort"<<endl;
- cout<<"Input the array size where size <= 20"<<endl;
- cin>>sizeIn;
- cout<<"Now read the Array"<<endl;
- sizeDet=read(array);
- if(sizeDet==sizeIn){
- sort(array,sizeIn); //Sort the array
- print(array,sizeIn);//Print the array
- }
- else {
- cout<<(sizeDet<sizeIn?"Input size less than specified.":"Input size greater than specified.")<<endl;
- }
- }
- https://d2vlcm61l7u1fs.cloudfront.net/media%2Fc36%2Fc36906c2-ebb9-4ba9-a773-8cd251ed903e%2FphpJgCbLZ.png
Advertisement
Add Comment
Please, Sign In to add comment