c++ - Why is this program crashing after it outputs a few elements -


#include <iostream> #include <ctime> #include <cstdlib> using namespace std;  int main() {     srand(time(null));     int sizer = (rand() % 15) + 2;     int nenad[sizer];     (int = 0; < sizer;i++)         nenad[i] = (rand() % 15) + 1;     (int = 0; < sizer;i++)         cout << nenad[i] << endl;     (int = 0; < sizer;i++)     {         (int j = + 1;i < sizer;j++)         {             if (nenad[i] > nenad[j])             {                 int temp = nenad[i];                 nenad[i] = nenad[j];                 nenad[j] = temp;             }         }     }     cout << "the biggest elements : " << nenad[sizer-1] << " , " << nenad[sizer-2] << endl; 

the program adds random amount of random numbers array. while they're being outputed program crashed. why?

your loop end condition seems curious, presume

for (int j = + 1;i < sizer;j++) 

should be

for (int j = + 1;j < sizer;j++) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -