Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tp56.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <math.h>
- int identiques (int *a, int *b);
- int valeursIidentiques (int *a, int *b);
- void echange (int *a, int *b);
- void saisieTemps(int *heures, int *minutes, int *secondes);
- int tempsValide(int *heures, int *minutes, int *secondes);
- float discriminant(float a, float b, float c);
- int nmbreRacines(float a, float b, float c);
- int resolutionEqua2ndDegre(float a, float b, float c, float *x1, float *x2);
- void onePGCDstep(int *a, int *b);
- int pgcd(int a, int b);
- int _tmain(int argc, _TCHAR* argv[])
- {
- int a, b;
- printf("a : ");
- scanf("%d", &a);
- printf("b : ");
- scanf("%d", &b);
- printf("pgcd(%d, %d) = %d\n", a, b, pgcd(a, b));
- scanf("\n");
- return 0;
- }
- int identiques (int *a, int *b)
- {
- if (a == b)
- return 1;
- else
- return 0;
- }
- int valeursIidentiques (int *a, int *b)
- {
- printf("pendant a : %d\n", *a);
- printf("pendant a : %d\n", *b);
- if (*a == *b)
- return 1;
- else
- return 0;
- }
- void echange (int *a, int *b) {
- int t = *a;
- *a = *b;
- *b = t;
- }
- void saisieTemps(int *heures, int *minutes, int *secondes)
- {
- do {
- printf("hh:mm:ss : ");
- scanf("%d:%d:%d", heures, minutes, secondes);
- } while (!tempsValide(heures, minutes, secondes));
- }
- int tempsValide(int *heures, int *minutes, int *secondes)
- {
- if (*secondes < 0 || *secondes > 60)
- return 0;
- if (*minutes < 0 || *minutes > 60)
- return 0;
- if (*heures < 0)
- return 0;
- return 1;
- }
- float discriminant(float a, float b, float c)
- {
- return b*b - 4*a*c;
- }
- int nmbreRacines(float a, float b, float c)
- {
- float discrim = discriminant(a, b, c);
- if (discrim > 0.) {
- return 2;
- } else if (discrim == 0.) {
- return 1;
- } else {
- return 0;
- }
- }
- int resolutionEqua2ndDegre(float a, float b, float c, float *x1, float *x2)
- {
- float discri = discriminant(a, b, c);
- switch (nmbreRacines(a, b, c)) {
- case 2:
- *x1 = (-b-sqrt(discriminant(a, b, c))) / (2*a);
- *x2 = (-b+sqrt(discriminant(a, b, c))) / (2*a);
- return 2;
- break;
- case 1:
- *x1 = -b/(2.*a);
- *x2 = *x1;
- return 1;
- break;
- default:
- *x1 = -1.;
- *x2 = -1.;
- return 0;
- break;
- }
- }
- void onePGCDstep(int *a, int *b)
- {
- int t = *b;
- *b = *a % t;
- *a = t;
- }
- int pgcd(int a, int b)
- {
- int c = a;
- int d = b;
- while (d > 0) {
- onePGCDstep(&c, &d);
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement