fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6.  
  7. bool IsAlready(int* arr, int p_number); //Check if the array has the number as its meber already.
  8.  
  9. void BubbleSort(int* arr);
  10. void PrintArray(int* arr, int count);
  11. void CompareArray(int* arr1, int* arr2, int count);
  12. int main() {
  13.  
  14. srand(time(NULL))
  15.  
  16. int* arr = new int[5]={nullptr};
  17. int number;
  18.  
  19.  
  20.  
  21. for(int i = 0 ; i<5; i ++)
  22. {
  23. while(1)
  24. {
  25. number = rand()%40 + 1;
  26.  
  27. if(IsAlready(arr, number) == true)
  28. continue;
  29. else
  30. {
  31. arr[i] = number;
  32. break;
  33. }
  34.  
  35. }
  36. }
  37. cout << "Created Array : ";
  38. PrintArray(arr,5);
  39.  
  40. cout << "Sorted Array : ";
  41. BubbleSort(arr);
  42. PrintArray(arr,5);
  43.  
  44. int* arr2 = new int[5];
  45. cout << "Input 5 numbers" ;
  46.  
  47. for(int i = 0 ; i<5; i ++)
  48. {
  49. cin >> arr2[i];
  50. }
  51.  
  52. PrintArray(arr2,5);
  53.  
  54. CompareArray(arr,arr2, 5);
  55.  
  56.  
  57.  
  58.  
  59. return 0;
  60. }
  61.  
  62. CompareArray(int* arr1, int* arr2, int p_countp_count)
  63. {
  64. int count = 0 ;
  65. for(int i = 0 ; i < p_count ; i ++ )
  66. {
  67. for(int j = 0 ; j < p_count; j ++)
  68. {
  69. if(arr2[j] == arr1[i])
  70. {
  71. count ++;
  72. break;
  73. }
  74. else continue;
  75. }
  76. }
  77. cout << count << endl;
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:2: error: expected ‘;’ before ‘int’
  int* arr = new int[5] = {nullptr};
  ^~~
prog.cpp:27:17: error: ‘arr’ was not declared in this scope
    if(IsAlready(arr, number) == true)
                 ^~~
prog.cpp:38:13: error: ‘arr’ was not declared in this scope
  PrintArray(arr,5);
             ^~~
prog.cpp: At global scope:
prog.cpp:62:54: error: ISO C++ forbids declaration of ‘CompareArray’ with no type [-fpermissive]
 CompareArray(int* arr1, int* arr2, int p_countp_count)
                                                      ^
prog.cpp: In function ‘int CompareArray(int*, int*, int)’:
prog.cpp:62:1: error: ambiguating new declaration of ‘int CompareArray(int*, int*, int)’
 CompareArray(int* arr1, int* arr2, int p_countp_count)
 ^~~~~~~~~~~~
prog.cpp:11:6: note: old declaration ‘void CompareArray(int*, int*, int)’
 void CompareArray(int* arr1, int* arr2, int count);
      ^~~~~~~~~~~~
prog.cpp:65:22: error: ‘p_count’ was not declared in this scope
  for(int i = 0 ; i < p_count ; i ++ )
                      ^~~~~~~
stdout
Standard output is empty