Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int numMult3(int nums[], int size);
- void removeAllMult3 (int nums[], int &size);
- void printArray(int nums[], int size);
- //////////////////////////////////////////////////////////////////////
- int main() //
- {
- int nums[100] = {30, 7, -21, 17, 10, 15, 18, 72, 3, 11, -40, 63};
- int size = 12;
- printArray(nums, size);
- cout << "\nThere are " << numMult3(nums, size)
- << " integers which are multiples of 3. \n" << endl;
- removeAllMult3(nums, size);
- printArray(nums, size);
- cout << "\nThere are " << numMult3(nums, size)
- << " integers which are multiples of 3. \n" << endl;
- return 0;
- }
- ////////////////////////////////////////////////////////////////////// complete this function
- int numMult3(int nums[], int size) //
- {
- int n = 0;
- for(int i = 0; i < size; i++)
- {
- if(nums[i] % 3 == 0) n++;
- }
- return n;
- }
- ////////////////////////////////////////////////////////////////////// complete this function
- void removeAllMult3(int nums[], int & size) //
- {
- int ni = 0;
- for(int i = 0; i < size; i++)
- {
- if(nums[i] % 3)
- {
- nums[ni] = nums[i];
- ni ++;
- }
- }
- size = ni;
- }
- //////////////////////////////////////////////////////////////////////
- void printArray(int nums[], int size)
- {
- for(int i = 0; i < size; i++) { cout << nums[i] << ", "; }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement