Код
# include <iostream.h>
# include <stdio.h>
# include <math.h>
# include <conio.h>
# include <alloc.h>
//-----------------------------------------------------------------
int Chislo(int x)
{
int j;
if (x<4) return 1;
else
{
for (j=2; j<ceil(sqrt(x))+1; j++)
if (x%j==0) return 0;
}
return 1;
}
//-----------------------------------------------------------------
/* int Sort()
{
return 0;
} */
//-----------------------------------------------------------------
int main()
{
clrscr();
int t,k,i2,j,j2,i,n; j=0; k=0;
cout<<"n="; cin>>n;
int* mas1 = new int[n];
int* mas2 = new int[n];
cout<<"El-ma \n"<<"\n";
for (i=0; i<n; i++)
{
cin>>mas1[i];
}
for (i=0; i<n; i++)
{
cout<<"\nmas1["<<i<<"]="<<mas1[i];
}
cout<<"\n";
//-----------------------------------------------------------------
for (i2=1; i2<n; i2++)
{
for (i=0; i<n-1; i++)
{
if (mas1[i]>mas1[i+1])
{
t=mas1[i];
mas1[i]=mas1[i+1];
mas1[i+1]=t;
}
}
}
//-----------------------------------------------------------------
for (i=0; i<n; i++)
{
cout<<"\nmas1["<<i<<"]="<<mas1[i];
}
cout<<"\n";
for (i=0; i<n; i++)
{
if (Chislo(mas1[i])==1) {mas2[j]=mas1[i]; j=j+1; k=k+1;}
}
for (j=0; j<k; j++)
{
cout<<"\nmas2["<<j<<"]="<<mas2[j];
}
cout<<"\n";
//-----------------------------------------------------------------
for (j2=1; j2<k; j2++)
{
for (j=0; j<k-1; j++)
{
if (mas2[j]<mas2[j+1])
{
t=mas2[j];
mas2[j]=mas2[j+1];
mas2[j+1]=t;
}
}
}
//-----------------------------------------------------------------
for (j=0; j<k; j++)
{
cout<<"\nmas2["<<j<<"]="<<mas2[j];
}
delete []mas1;
delete []mas2;
getch();
return 0;
}
# include <stdio.h>
# include <math.h>
# include <conio.h>
# include <alloc.h>
//-----------------------------------------------------------------
int Chislo(int x)
{
int j;
if (x<4) return 1;
else
{
for (j=2; j<ceil(sqrt(x))+1; j++)
if (x%j==0) return 0;
}
return 1;
}
//-----------------------------------------------------------------
/* int Sort()
{
return 0;
} */
//-----------------------------------------------------------------
int main()
{
clrscr();
int t,k,i2,j,j2,i,n; j=0; k=0;
cout<<"n="; cin>>n;
int* mas1 = new int[n];
int* mas2 = new int[n];
cout<<"El-ma \n"<<"\n";
for (i=0; i<n; i++)
{
cin>>mas1[i];
}
for (i=0; i<n; i++)
{
cout<<"\nmas1["<<i<<"]="<<mas1[i];
}
cout<<"\n";
//-----------------------------------------------------------------
for (i2=1; i2<n; i2++)
{
for (i=0; i<n-1; i++)
{
if (mas1[i]>mas1[i+1])
{
t=mas1[i];
mas1[i]=mas1[i+1];
mas1[i+1]=t;
}
}
}
//-----------------------------------------------------------------
for (i=0; i<n; i++)
{
cout<<"\nmas1["<<i<<"]="<<mas1[i];
}
cout<<"\n";
for (i=0; i<n; i++)
{
if (Chislo(mas1[i])==1) {mas2[j]=mas1[i]; j=j+1; k=k+1;}
}
for (j=0; j<k; j++)
{
cout<<"\nmas2["<<j<<"]="<<mas2[j];
}
cout<<"\n";
//-----------------------------------------------------------------
for (j2=1; j2<k; j2++)
{
for (j=0; j<k-1; j++)
{
if (mas2[j]<mas2[j+1])
{
t=mas2[j];
mas2[j]=mas2[j+1];
mas2[j+1]=t;
}
}
}
//-----------------------------------------------------------------
for (j=0; j<k; j++)
{
cout<<"\nmas2["<<j<<"]="<<mas2[j];
}
delete []mas1;
delete []mas2;
getch();
return 0;
}