user input of significant figures

hi i am writing a program that computes the simpsons rule, i would like the user to input how many significant figures the program should output to, can anyone help? i already have it outputting to 15

#include <stdio.h>
#include <math.h>
using namespace std;

// This is the function we seek to integrate
double f(double x)
{
return exp(-x)*sin (x);
}

// Compute an approximation to the integral
// of f(x) from a to b by using simpson's rule
// with steps of size (b-a)/n
double integrate(double a,double b,int n)
{
double h,sum,x0,term;
int k;

h = (b - a)/n;
sum = 0.0;

for(k = 0;k < n;k++)
{
x0 = a + k*h;
term = h*(f(x0)+4*f(x0+h/2)+f(x0+h))/6;
sum += term;
}

return sum;
}

int main (int argc, const char * argv[])
{
int k,n, s ; // s= number of significant figures
FILE* output;

printf("how many significant figures would you like your answer accurate to") ;
scanf("%d",&s); // scans number of significant figures
output = fopen("table.txt","w");

fprintf(output," n estimate\n");
for(n = 10,k = 1;k < 8;n *= 10,k++)
fprintf(output,"%8d %.14f\n",n,integrate(0.0,2.0,n));

fclose(output);

return 0;
}

Topic archived. No new replies allowed.