Advertisement
Wyvern67

Temp C

Feb 8th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. ___Après déclaration___
  2. Degré: 4
  3. 0
  4. 0
  5. 0
  6. 0
  7. ___Après passage en argument___
  8. Degré: 4
  9. 0
  10. 0
  11. 0
  12. 0
  13. ___Dans le main après dérivée___
  14. Degré: 3
  15. 0
  16. 0
  17. 0
  18. 0
  19. [Finished in 0.0s]
  20.  
  21. #include <stdio.h>
  22.  
  23. #define N 100
  24.  
  25. typedef struct {
  26.     int degree;
  27.     float coeff[N+1];
  28. } polynomial;
  29.  
  30. polynomial derivative(polynomial pol)
  31. {
  32.     int i;
  33.     printf("Degré: %d\n", pol.degree);
  34.     printf("%d\n", pol.coeff[0]);
  35.     printf("%d\n", pol.coeff[1]);
  36.     printf("%d\n", pol.coeff[2]);
  37.     printf("%d\n", pol.coeff[3]);
  38.     printf("_______\n");
  39.     for (i=1; i<=pol.degree; i++)
  40.     {
  41.         //i parcourt les degrés du poly de 1 à N
  42.         //coeff[i] le coeff du membre de degré i
  43.         pol.coeff[i-1] = pol.coeff[i] * i;
  44.         // 4*x^2 ==> 8*x^1
  45.     }
  46.     pol.coeff[pol.degree] = 0;
  47.     pol.degree--;
  48.     return pol;
  49. }
  50.  
  51. int main(int argc, char const *argv[])
  52. {
  53.     polynomial pol = {4, {1,2,3,4}};
  54.     printf("___Après déclaration___\n");
  55.     printf("Degré: %d\n", pol.degree);
  56.     printf("%d\n", pol.coeff[0]);
  57.     printf("%d\n", pol.coeff[1]);
  58.     printf("%d\n", pol.coeff[2]);
  59.     printf("%d\n", pol.coeff[3]);
  60.  
  61.     pol = derivative(pol);
  62.     printf("___Dans le main après dérivée___\n");
  63.     printf("Degré: %d\n", pol.degree);
  64.     printf("%d\n", pol.coeff[0]);
  65.     printf("%d\n", pol.coeff[1]);
  66.     printf("%d\n", pol.coeff[2]);
  67.     printf("%d\n", pol.coeff[3]);
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement