C++ Random Prime Numbers 0-100 (CRPN)

Case study:

Create a program to randomize prime numbers from 100 input numbers, using C++ programming!

Solution:

Source code:

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

/**
*bundet.com
*Acak Bilangan Prima 0-100
*/

void main(){
int nilai[100],x;
randomize();
cout << "100 angka yang diinputkan, dan bilangan prima yang diperoleh secara acak : " <<endl<<endl;

 for (int i=0; i<100; i++){
  nilai[i]=random(100);
  x=0;
  for (int j=2; j<=nilai [i]; j++){
       if (nilai[i]%j==0){
   x++;
    }
  }
 if (x==1 && nilai [i]!=0){
  cout <<nilai[i]<<" ";
  }
 }
getch();
}

Hope this is useful & happy learning!


Post a Comment

Previous Next

نموذج الاتصال