Blame view

derniers_exos.c 618 Bytes
0e3aac2d   Pierre Cwik   ansi fait
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <stdio.h>
  #include <stdint.h>
  #include <stdlib.h>
  #include <stdbool.h>
  #define erreur(message) { fprintf(stderr,message) ; exit(EXIT_FAILURE); }
  int premier(int n){
  int taille=n*n+1;
  int result=-1;
    int *crible = malloc( taille * sizeof(int) );
  int i;
  for(i=0;i<=n*n;i++) crible[i]=true;
  for(i=2;i<=n;i++)
    if(crible[i]){
      int j=i*i;
      while(j<=n*n){ crible[j]=false; j += i; }
      }
  for(i=n*n;i>=0;i--) if(crible[i]){ result=i; break; }
  return result;
  }
  
  int main(void){
  int n;									
  if(scanf("%d",&n)!=1) erreur("Echec de lecture du nombre\n");
  printf("premier -> %d\n",premier(n));
  return 0;
  }