Programmation en c
slt pardon jaimerais avoir votre aide. j'ai un programme et jai essayer mai ca ne donne pas. aidez moi svp. je suis debutante en informatique medicale.
ecrire un programme permettant d'afficher les 100 nombres premiers et le temps que ca met pour afficher. jai essayer et voici mon code qui je fonctionne pas
merci
#include "stdafx.h"
#include "stdio.h"
#include <time.h>
#include <math.h>
long int primzahl(long int max);
long int test(long int t);
int main()
{
float temps;
long int erg;
long int t1, t2;
long int max = 0;
printf("afficher le max");
scanf("%d", &max);
t1 = clock();
erg = nbrePremier(max);
t2 = clock();
temps = (t2-t1)/CLOCKS_PAR_SEC;
printf("\n temps: %10.2f sec \n", temps);
return 0;
}
long int nbrePremier( long int max)
{ long int i;
for (i = max; i > 1; i--)
{
if (test(i) == 1) return i;
}
return 2;
}
long int test( long int t) {
int j;
for (j = 2; j*j<=t; j++)
{
if (t%j== 0) return 0;
}
return 1;
}
ecrire un programme permettant d'afficher les 100 nombres premiers et le temps que ca met pour afficher. jai essayer et voici mon code qui je fonctionne pas
merci
#include "stdafx.h"
#include "stdio.h"
#include <time.h>
#include <math.h>
long int primzahl(long int max);
long int test(long int t);
int main()
{
float temps;
long int erg;
long int t1, t2;
long int max = 0;
printf("afficher le max");
scanf("%d", &max);
t1 = clock();
erg = nbrePremier(max);
t2 = clock();
temps = (t2-t1)/CLOCKS_PAR_SEC;
printf("\n temps: %10.2f sec \n", temps);
return 0;
}
long int nbrePremier( long int max)
{ long int i;
for (i = max; i > 1; i--)
{
if (test(i) == 1) return i;
}
return 2;
}
long int test( long int t) {
int j;
for (j = 2; j*j<=t; j++)
{
if (t%j== 0) return 0;
}
return 1;
}
A voir également:
- Programmation en c
- Application programmation - Guide
- Programmation visual basic - Télécharger - Langages
- Mettre en veille un programme - Guide
- Programmation sms - Guide
- Programmation binaire - Guide
1 réponse
Tu peux t'inspirer de ceci :
https://stackoverflow.com/questions/22485655/program-to-display-prime-numbers
Bonne chance
https://stackoverflow.com/questions/22485655/program-to-display-prime-numbers
Bonne chance