Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ___Après déclaration___
- Degré: 4
- 0
- 0
- 0
- 0
- ___Après passage en argument___
- Degré: 4
- 0
- 0
- 0
- 0
- ___Dans le main après dérivée___
- Degré: 3
- 0
- 0
- 0
- 0
- [Finished in 0.0s]
- #include <stdio.h>
- #define N 100
- typedef struct {
- int degree;
- float coeff[N+1];
- } polynomial;
- polynomial derivative(polynomial pol)
- {
- int i;
- printf("Degré: %d\n", pol.degree);
- printf("%d\n", pol.coeff[0]);
- printf("%d\n", pol.coeff[1]);
- printf("%d\n", pol.coeff[2]);
- printf("%d\n", pol.coeff[3]);
- printf("_______\n");
- for (i=1; i<=pol.degree; i++)
- {
- //i parcourt les degrés du poly de 1 à N
- //coeff[i] le coeff du membre de degré i
- pol.coeff[i-1] = pol.coeff[i] * i;
- // 4*x^2 ==> 8*x^1
- }
- pol.coeff[pol.degree] = 0;
- pol.degree--;
- return pol;
- }
- int main(int argc, char const *argv[])
- {
- polynomial pol = {4, {1,2,3,4}};
- printf("___Après déclaration___\n");
- printf("Degré: %d\n", pol.degree);
- printf("%d\n", pol.coeff[0]);
- printf("%d\n", pol.coeff[1]);
- printf("%d\n", pol.coeff[2]);
- printf("%d\n", pol.coeff[3]);
- pol = derivative(pol);
- printf("___Dans le main après dérivée___\n");
- printf("Degré: %d\n", pol.degree);
- printf("%d\n", pol.coeff[0]);
- printf("%d\n", pol.coeff[1]);
- printf("%d\n", pol.coeff[2]);
- printf("%d\n", pol.coeff[3]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement