#include<conio.h>
#include<stdio.h>
#include <stdlib.h>
#include<time.h>
#define N 25
#define K 3
int prime(int num)
{ int i;
for(i=2;i<=num/2;i++)
if(num%i==0) break;
if(i==num/2+1 || num==1) return num;
else return 0;
}
int maxPos(int A[])
{ int i,max,mPos;
max=0;
for(i=0;i<N;i++)
if(A[i]>max)
{ max=A[i];
mPos=i;
return mPos;
int main()
{ int i,j,X[N],Y[N],pos;
srand(time(NULL));
{ X[i]=rand()%30+1;
Y[i]=prime(X[i]);
printf("Original array\n");
printf("%3d",X[i]);
printf("\nArray-masque of prime numbers\n");
printf("%3d",Y[i]);
printf("\n\n");
for(j=0;j<K;j++)
{ pos=maxPos(Y);
printf("%3d in position %3d targeted\n",X[pos],pos);
Y[pos]=-1;
X[pos]=-1;
j=0;
if(X[i]!=-1)
{ Y[j]=X[i];
j++;
printf("\nResult:\n");
for(i=0;i<j;i++)
getchar();
return 0;
Объяснение:
#include<conio.h>
#include<stdio.h>
#include <stdlib.h>
#include<time.h>
#define N 25
#define K 3
int prime(int num)
{ int i;
for(i=2;i<=num/2;i++)
if(num%i==0) break;
if(i==num/2+1 || num==1) return num;
else return 0;
}
int maxPos(int A[])
{ int i,max,mPos;
max=0;
for(i=0;i<N;i++)
if(A[i]>max)
{ max=A[i];
mPos=i;
}
return mPos;
}
int main()
{ int i,j,X[N],Y[N],pos;
srand(time(NULL));
for(i=0;i<N;i++)
{ X[i]=rand()%30+1;
Y[i]=prime(X[i]);
}
printf("Original array\n");
for(i=0;i<N;i++)
printf("%3d",X[i]);
printf("\nArray-masque of prime numbers\n");
for(i=0;i<N;i++)
printf("%3d",Y[i]);
printf("\n\n");
for(j=0;j<K;j++)
{ pos=maxPos(Y);
printf("%3d in position %3d targeted\n",X[pos],pos);
Y[pos]=-1;
X[pos]=-1;
}
j=0;
for(i=0;i<N;i++)
if(X[i]!=-1)
{ Y[j]=X[i];
j++;
}
printf("\nResult:\n");
for(i=0;i<j;i++)
printf("%3d",Y[i]);
getchar();
return 0;
}
Объяснение: