write a programe to find and count the total occurencies of multiple of 2,3,4,5 in 100 elements
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
void fill_array(int (&array)[100])
{
srand((int)time(NULL));
for (int j = 0; j < 100; j++)
array[j] = rand() % 5 + 1;
}
void print_array(int (&array)[100])
{
for (int q = 0; q < 100; q++)
{
if (q % 10 == 0)
cout << endl;
cout << "& " << array[q];
}
cout << endl;
}
int count_multiples(int (&array)[100])
{
int result = 0;
bool multipleFound;
for (int b = 0; b < 96; b++)
{
multipleFound = true;
for (int num = 2; num <= 5; num++)
if (array[b + num - 2] != num)
{
multipleFound = false;
break;
}
if (multipleFound)
result++;
else
b += 3;
}
}
int main()
{
int array[100];
fill_array(array);
print_array(array);
cout << "The number of multiples of {2, 3, 4, 5} found: " << count_multiples(array) << endl;
_getch();
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++