Advertisement
ismaeil

Numbers that are divisible by 5

Jun 20th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int NewSize = 0;
  6.  
  7. int * ArrDiv5(int *arr ,int Size){
  8.  
  9.     for(int i=0 ; i < Size ; i++){
  10.         if( arr[i] % 5 == 0 )
  11.             NewSize ++;
  12.     }
  13.  
  14.     int idx = 0;
  15.     int *Re = new int[ NewSize ];
  16.  
  17.     for(int i=0 ; i < Size ; i++){
  18.         if( arr[i] % 5 == 0 ){
  19.             Re[idx] = arr[i];
  20.             idx++;
  21.         }
  22.     }
  23.  
  24.     return Re;
  25. }
  26.  
  27. int main()
  28. {
  29.     int Size;
  30.     cout << "Enter The Size Of The Original Array : ";
  31.     cin >> Size;
  32.  
  33.     int *arr = new int[Size];
  34.     cout << "Enter " << Size << "Elements :" << endl;
  35.     for(int i=0 ; i < Size ; i++){
  36.         cin >> arr[i];
  37.     }
  38.  
  39.     cout << "Numbers that are divisible by 5 : " << endl;
  40.     int * Ans = ArrDiv5(arr ,Size);
  41.     for(int i=0 ; i < NewSize ; i++){
  42.         cout << setw(4) << Ans[i];
  43.     }
  44. }
  45. /*
  46. 5
  47. 10 11 15 23 30
  48. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement