jaredec18

Untitled

Sep 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5.  
  6. int read(char array[]){
  7. int count = 0;
  8. cin >> array;
  9. return strlen(array);
  10. }
  11.  
  12. void sort(char array[], int size){
  13. for (int i = 0; i<size; i++){
  14. for (int j = i + 1; j<size; j++){
  15. if (array[i] > array[j]){
  16. char temp = array[i];
  17. array[i] = array[j];
  18. array[j] = temp;
  19. }
  20. }
  21. }
  22. }
  23.  
  24. void print(char array[], int size){
  25. for (int i = 0; i<size; i++)
  26. cout << array[i];
  27. cout << endl;
  28. }
  29.  
  30. int main(){
  31.  
  32. const int SIZE = 80;
  33. char array[SIZE];
  34. int sizeIn, sizeDet;
  35.  
  36. cout<<"Read in a 1 dimensional array of characters and sort"<<endl;
  37. cout<<"Input the array size where size <= 20"<<endl;
  38. cin>>sizeIn;
  39. cout<<"Now read the Array"<<endl;
  40. sizeDet=read(array);
  41. if(sizeDet==sizeIn){
  42. sort(array,sizeIn); //Sort the array
  43. print(array,sizeIn);//Print the array
  44. }
  45. else {
  46. cout<<(sizeDet<sizeIn?"Input size less than specified.":"Input size greater than specified.")<<endl;
  47. }
  48. }
  49.  
  50. https://d2vlcm61l7u1fs.cloudfront.net/media%2Fc36%2Fc36906c2-ebb9-4ba9-a773-8cd251ed903e%2FphpJgCbLZ.png
Advertisement
Add Comment
Please, Sign In to add comment