Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5.  
  6. double * aitken(double * x, int n) {
  7.  
  8. double * y = NULL;
  9. int j = 0;
  10.  
  11. y = malloc ((n-2)*sizeof(double));
  12. assert (y != NULL);
  13.  
  14. for (j = 0; j < n-2; j++) {
  15.  
  16. y[j]= x[j] - ((x[j+1]-x[j])*(x[j+1]-x[j]))/(x[j+2]-2*x[j+1]+x[j]);
  17.  
  18. }
  19.  
  20. return y;
  21. }
  22.  
  23. double * scanVector( int dim){
  24.  
  25. int j = 0;
  26. double * vector = NULL;
  27. assert (dim > 0);
  28.  
  29.  
  30. vector= malloc(dim*sizeof(double));
  31. assert(vector != NULL);
  32.  
  33. for (j = 0 ; j < dim; j++) {
  34. printf("Geben Sie die %dte Stelle der Folge ein:",j);
  35. scanf("%lf",&vector[j]);
  36.  
  37.  
  38. }
  39. return vector;
  40. }
  41.  
  42.  
  43. double * printVector(double*vector, int dim) {
  44. int j = 0;
  45. assert (dim > 0);
  46. assert (vector != NULL);
  47. for (j = 0; j< dim-2; j++) {
  48.  
  49. printf("y[%f]\n",vector[j]);
  50.  
  51. }
  52.  
  53. }
  54.  
  55. int main () {
  56.  
  57.  
  58. int n = 0;
  59. double *x = NULL;
  60. double *y = NULL;
  61.  
  62. printf("Geben Sie eine Anzahl der Folgenglieder n (n>3) ein:");
  63. scanf("%d",&n);
  64.  
  65. assert (n > 3);
  66.  
  67. x=scanVector(n);
  68.  
  69.  
  70. y=aitken(x,n);
  71.  
  72. printVector(y,n);
  73.  
  74. free (x);
  75. free (y);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement