vendredi 7 avril 2017

Nested for loop array random numbers

So what i am trying to do is to print out 7 random numbers and the loop should not print out duplicates. When i am trying to debug it seems that i don't get in to my nested loop where my if statement is.

i also get a memory value printed out and the random numbers is duplicated.

I believe there is something wrong in my 2nd nested for loop but i cant figure out what, would appreciate some help if someone can see the issue and explain to me what's happening with my nested 2nd loop, step by step.

#include <stdio.h>
#include <time.h>
#define SIZE 35

int main()
{
int number[SIZE];

srand(time(NULL));

for (int i = 1; i < 7; i++)
{
    number[i] = rand() % 35 + 1;
    for (int j = 0; j > i; j++)
    {
        if (number[i] == number[i])
        printf("%d\n", number[i]);
        i--;
    }
}
for (int i = 0; i < 7; i++)
{
    printf("%d\n", number[i]);
}
getchar();

return 0;
}




Aucun commentaire:

Enregistrer un commentaire