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:37am
C++ Code
[
Download
]
/* Initial Inputs: Calculate the 3-rd moment 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]; double k = 3.0; // 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]<< endl; } for(int i=0; i < nmax; i++) { moment = moment + pow(rand_x[i],k); } // Calculates k'th moment final_moment = (1.0 / nmax) * moment; cout << endl << k << "rd moment is: " << final_moment << endl << endl; system("pause"); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.41 / 8
205 Votes
http://codebin.yi.org/264
page generated in 0.00 seconds