Skip to content

Instantly share code, notes, and snippets.

@nickcharlton
Forked from anonymous/butts.c
Created December 6, 2011 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickcharlton/1438545 to your computer and use it in GitHub Desktop.
Save nickcharlton/1438545 to your computer and use it in GitHub Desktop.
butts
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "mt64.h"
int n,i; //Define n and i as integers
double *array; //Dynamic array as a double
FILE *myfile;
int main()
{
printf("How many numbers would you like? \n");
scanf("%d",&n); //Scans for an integer the user enters
array = (double*)malloc(n*sizeof(double)); //Something something dynamic array?
init_genrand64(time(NULL)); //Sets the seed for the random number generator
for (i=0;i<n;i++) //Loops from i=0 to i=n, increments of 1
{
array[i]=genrand64_real3(); //Assigns a random number to element n of the array
printf("Array element %d is %f \n",i,array[i]); //Prints the array element value
}
i=0; //Reset i to 0
myfile=fopen("prototype.txt","w"); //Open prototype.txt
for (i=0;i<n;i++)
{
fprintf(myfile,"%f\n",array[i]); //Print a number from the array on
}
fclose(myfile);
free(array); //Frees the array?
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment