Advertisement
lineoff

schema horner

Jan 11th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  sHorner
  4. //
  5. //  Created by MacBook Pro on 18/10/2015.
  6. //  Copyright © 2015 MacBook Pro. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include "stdlib.h"
  11.  
  12. int main(int argc, const char * argv[]) {
  13.     int *a,n;
  14.     int i=0;
  15.     float x;
  16.     double p;
  17.     p=0;
  18.     printf("Donner le degre de P: ");
  19.     scanf("%d",&n);
  20.     a = (int*)malloc((n+1)*sizeof(int));
  21.     printf("Donner la valeur de x: ");
  22.     scanf("%f",&x);
  23.     printf("donner les coefficients du P:\n");
  24.     while(i<n+1){
  25.         printf("Donner le coefficient %d: ",n-i);
  26.         scanf("%d",a+i);
  27.         i++;
  28.     }
  29.     i=1;
  30.     p = *(a+n);
  31.     while (i<n+1) {
  32.         p =p*x+ *(a+n-i);
  33.         i++;
  34.     }
  35.    
  36.     printf("le resultat est %f\n",p);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement