Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int NewSize = 0;
- int * ArrDiv5(int *arr ,int Size){
- for(int i=0 ; i < Size ; i++){
- if( arr[i] % 5 == 0 )
- NewSize ++;
- }
- int idx = 0;
- int *Re = new int[ NewSize ];
- for(int i=0 ; i < Size ; i++){
- if( arr[i] % 5 == 0 ){
- Re[idx] = arr[i];
- idx++;
- }
- }
- return Re;
- }
- int main()
- {
- int Size;
- cout << "Enter The Size Of The Original Array : ";
- cin >> Size;
- int *arr = new int[Size];
- cout << "Enter " << Size << "Elements :" << endl;
- for(int i=0 ; i < Size ; i++){
- cin >> arr[i];
- }
- cout << "Numbers that are divisible by 5 : " << endl;
- int * Ans = ArrDiv5(arr ,Size);
- for(int i=0 ; i < NewSize ; i++){
- cout << setw(4) << Ans[i];
- }
- }
- /*
- 5
- 10 11 15 23 30
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement