The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C++ Code
Posted by: bdizzle | March 25, 2009 @ 12:24am
C++ Code
[
Download
]
/* Physics 420 March 24, 2009 HW #8, Problem #1 ------------------------------------------------ Initial Inputs: Calculate the near-neighbor correlation of the random number distribution Output Outputs random numbers to screen */ // generate integer random numbers between i1 and i2 #include <iostream> #include <cstdlib> #include <cmath> #include <ctime> using namespace std; int main () { int nmax=100; /* generate 10 random numbers*/ int i1=1, i2=6, irandom; int rand_x[nmax]; int k = 3; // degree of moment int moment = 0; double final_moment = 0.0; srand (469); /* initial seed for x-values*/ //srand(time(NULL)); // better to "randomize" seed values for (int i=0; i < nmax; i=i+1) { rand_x[i] = i1+rand()%(i2-i1+1); //number between i1 & i2*/ cout << " " << rand_x[i] << " " << moment<< endl; } for(int i = 0; i < nmax, i++) { moment = moment + rand_x[i]*rand_x[i+k]; } // Calculates k'th moment final_moment = (1.0 / nmax) * moment; cout << endl << k << "th moment is: " << final_moment << endl << endl; system("pause"); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.53 / 8
191 Votes
http://codebin.yi.org/262
page generated in 0.00 seconds