#include<iostream>
#include<fstream>
#include<math.h>
#include<stdlib.h>
using namespace std;

/* Echantillonnage d'une fonction */

double g(double x){
  return sin(x);
}

void ech(double (*f)(double), double xmin, double xmax, int n, double* t){
  int i;
  double h;

  h = (xmax-xmin) / (n-1);
  for (i = 0; i < n; i++)
    t[i] = (*f)(xmin + h*i);
}

int main(){
  int N = 100;
  double xmin = 0.;
  double xmax = 2.*M_PI;
  double* t = (double*)malloc(N * sizeof(double));
  int i;
  fstream fich;

  ech(g, xmin, xmax, N, t);
  fich.open("echantillonnage.res", ios::out);
  for (i = 0; i < N; i++){
    cout << t[i] << endl;
    fich << t[i] << endl;
  }
  fich.close();
  free(t);
  return 0;
}
