SHARE
TWEET

Untitled

a guest Nov 12th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int nbPrem(int res, int table[]){
  6.     cout << "ici";
  7.   int i,pn,c,k;
  8.   for(i=2;i<=res;i++){
  9.     table[i]=i;
  10.   }
  11.   pn=table[2];
  12.   c=1;
  13.   k=2;
  14.   cout << "ici";
  15.   int lim=pow(res,0.5);
  16.   while(pn<=lim){
  17.     while(table[k]==-1){
  18.       k++;
  19.     }
  20.     pn=table[k];
  21.     for(i=pn+1;i<=res;i++){
  22.       if(table[i]%pn==0){
  23.         table[i]=-1;
  24.       }else{
  25.         c++;
  26.       }
  27.     }
  28.   }
  29.   return(c);
  30. }
  31.  
  32. int main(){
  33.   int n,i,k,c;
  34.   cout << "Jusqu'à combien voulez-vous rechercher des nombres premiers ? : ";
  35.   cin >> n;
  36.   int table[n];
  37.   c=nbPrem(n, table);
  38.   int nbp[c];
  39.   k=2;
  40.   for(i=0;i<=c;i++){
  41.     while(table[k]==-1){
  42.       k++;
  43.     }
  44.     nbp[i]=table[k];
  45.   }
  46.   cout << "\nListe des nombres premiers jusqu'à " << n << " : ";
  47.   for(i=0;i<=c;i++){
  48.     cout << nbp[c] << ", ";
  49.   }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top