Commit 6e6b2501 authored by Louis Malevez's avatar Louis Malevez

Fonction qui factorise en facteur premier

parent 6926cfcf
//
// Created by Louis Malevez on 19-04-20.
//
#ifndef PROJET_Q4_GROUPE_O4_PRIMEF_H
#define PROJET_Q4_GROUPE_O4_PRIMEF_H
# include <stdio.h>
# include <math.h>
int primeFactors(int n, FILE*f_out);
int primeFactors(int n,FILE*f_out){// prends un fichier et écrit un entier et ses diviseurs dedans
int count1=0;
int count2=0;
fprintf(f_out,"%d ",n);
while (n%2 == 0)
{
if(count1==0) fprintf(f_out,"%d ", 2);
n = n/2;
count1+=1;
}
for (int i = 3; i*i <= n; i = i+2)
{
while (n%i == 0){
if(count2==0) fprintf(f_out,"%d ", i);
n=n/i;
count2+=1;
}
count2=0;
}
if (n > 2)
fprintf (f_out,"%d ", n);
fprintf(f_out,"\n");//passe à la ligne qd c'es terminé
return 0;
}
#endif //PROJET_Q4_GROUPE_O4_PRIMEF_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment