Thankyou so much for your help, I went out today and got programming in C for dummies, was very helpful. I was able to write the array Z[j] to a txt file. However when I open it up in excel it comes up with a Text Import Wizard where I have to sort out columns to import the data. Is there a way to write the code so I don't have to go through this text import wizard?
Here is my new code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NUM_ELEMENTS 1000
int main()
{
int i,j, zed;
float x[ NUM_ELEMENTS],y[ NUM_ELEMENTS], u=0.25, m=0.5;
double z[ NUM_ELEMENTS], w[ NUM_ELEMENTS], a[ NUM_ELEMENTS], b[ NUM_ELEMENTS];
for(i=0;i<1000;i++)
{
x[i] = 2*((float)rand()/(float)RAND_MAX)-1;
y[i] = 2*((float)rand()/(float)RAND_MAX)-1;
a[i]= pow(x[i],2);
b[i]= pow(y[i],2);
w[i] = (a[i]+b[i]);
}
j=0;
for(i=0;i<1000;i++)
{
if(w[i]<1)
{(z[j]=((u*x[i])
*(sqrt((-1*2)
*(log(w[i])
/(w[i])))))+m);
j++;
}
}
zed = j;
for(j=0;j<zed;j++)
{
printf("%f\t",z[j]);
}
FILE *myfile;
myfile = fopen("program.txt","w");
if(!myfile)
{
puts("some kind of file error!");
return(1);
}
zed = j;
for(j=0;j<zed;j++)
{
fprintf(myfile, "%3d %f\n",j,z[j]);
}
fclose(myfile);
return 0;
}