Difference between revisions of "CPP/Array"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==Array.cpp== <source lang="cpp"> #include <iostream> double* ReturnArray(); int main() { double a[3]; a[0] = 0.5; a[1] = 1.5; a[2] = 2.5; std::cout << a[0] << …') |
FirstPerson (Talk | contribs) (→Array.cpp) |
||
Line 2: | Line 2: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
#include <iostream> | #include <iostream> | ||
− | + | #include <ctime> | |
− | + | ||
+ | using namespace std; | ||
+ | |||
int main() | int main() | ||
− | { | + | { |
− | + | srand(time(0)); //seed random number generator | |
− | + | const int maxSize = 10; | |
− | + | int rawArray[maxSize] = {0}; // 0 0 0 0 0 0 0 0 0 0 | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | // generate 10 random numbers | |
− | + | for(int i = 0; i < maxSize; ++i) rawArray[i] = rand(); | |
+ | for(int j = 0; j < maxSize; ++j) cout << rawArray[j] << " "; | ||
+ | |||
+ | return 0; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
+ | |||
</source> | </source> |
Latest revision as of 23:37, 15 July 2010
Array.cpp
#include <iostream> #include <ctime> using namespace std; int main() { srand(time(0)); //seed random number generator const int maxSize = 10; int rawArray[maxSize] = {0}; // 0 0 0 0 0 0 0 0 0 0 // generate 10 random numbers for(int i = 0; i < maxSize; ++i) rawArray[i] = rand(); for(int j = 0; j < maxSize; ++j) cout << rawArray[j] << " "; return 0; }