下面是偶写的,偶算法不好.
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define SIZE 101
#define MAX 200
void print(int *num ,int N) {
int i = 0;
for(; i < N; i++)
if( num[i] )
printf("%d ",num[i] );
}
int* judge(int *num, int N) {
int i = 0;
int j = 2;
for( i = 0; i< N; i++){
for(j = 2; j < sqrt(MAX) ; j++ )
if(num[i] != j&&num[i] % j == 0 ){
num[i] = 0;
break;
}
}
return num;
}
int main(void){
int * num = (int* )malloc(SIZE*sizeof(int));
int i = 0, j = 100;
for( ; i < SIZE ; i++)
num[i] = j++;
print(judge(num,SIZE),SIZE);
free(num);
return 0;
}
[[it] 本帖最后由 中学者 于 2008-4-17 15:14 编辑 [/it]]