Professional Documents
Culture Documents
6 1
6 1
#include<stdlib.h>
#include<time.h>
void inputr()
{
srand((unsigned)(time(NULL)));
cout << "enter number of the components (<=30)" << endl;
cin >> n;
while (n <= 0 || n > 30)
{
cout << "n>0 and n<=30" << endl;
cin >> n;
}
for (int i = 0; i < n; i++)
a[i] = rand() % 100;
cout << "Generated array" << endl;
void inputk()
{
cout << "enter number of the components (<=30)" << endl;
cin >> n;
while (n <= 0 || n > 30)
{
cout << "n>0 and n<=30" << endl;
cin >> n;
}
//�������� ������
void output()
{
for (int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
}
//����� �����
void Primenum()
{
cout << "Prime numbers: ";
for (int i = 0; i < n; i++)
{
for (int j = 2; j <= a[i] / 2; j++)
{
if (a[i] % j == 0 && a[i] != j)
{
a[i] = 0;
break;
}
}
if (a[i] != 0)
{
cout << a[i] << " ";
}
}
}
int main()
{
int e, p;
cout << "1.Array generation randomly" << endl;
cout << "2.Generating an array from the keyboard" << endl;
cin >> e;
switch (e)
{
case 1:
inputr();
break;
case 2:
inputk();
break;
}
output();
Primenum();
cout << endl;
cout << "Do you want to repeat?(1 Yes/ 2 No)";
cout << endl;
cin >> p;
while (p != 1 && p != 2)
{
cout << "1 Yes/ 2 No" << endl;
cin >> p;
}
switch (p) {
case 1:
{
system("cls");
main();
}
break;
case 2:
return 0;
break;
system("pause");
return 0;
}
}