phat sinh so

// phat sinh ngau nhien ma cac so nguyen tu1 den 100

int my_rand(int a,int b)

{

return rand()%(b-a+1)+a;

}

int So_nguyen_to(int n)

{ if(n<2) return 0;

if(n==2) return 1;

int m=round(sqr+(n));

for(int i=2;i<m;i++)

if(n%i==0)

return 0;

return 1;

}

void xuat(int a[],int n)

{

for(int i=0;i<n;i++)

cout<<a[i]<<"";

cout<<endl;

}

void nhap(int a[],int n)

{

for(int i=0;i<n;i++)

a[i]=my_rand(1,100);

}

int dem(int a[],int n)

{

int d=0;

for(int i=0;i<n;i++)

if(so_nguyen_to(a[i]))

++d;

return d;

}

void main()

{

srand((unsigned)time(null));

int a[100],n;

cout<<"so phan tu cua mang";

cin>>n;

nhap(a,n);

cout<<"Mang phat sinh ngau nhien";

xuat(a,n);

cout<<"co"<<dem(a,n)<<"So nguyen to trong mang"<<endl;

}

Bạn đang đọc truyện trên: TruyenTop.Vip

Tags: