T
Tadpole
Hi,
Can anyone explain what is happening?
int x=0;
srand (time(NULL));
for (int i=0;i <100; i++)
{x =rand ()%9;
if ( x !=( 7||8))
printf ("%d ",x);
}
Result of Print
5 8 7 4 8 3 0 7 2 8 2 7 6 7 5 7 8 3 0 0 6 5 0 4 7 6 5 8 5 2 0 2 0 6 4 8 7 3
2 6
2 3 6 2 3 7 2 5 5 6 3 7 2 3 7 4 4 2 5 6 0 4 5 4 4 5 0 5 6 7 5 3 6 3 2 0 5 0
0 5
7 5 8 6 3 2 2 8 3 6 8
Press any key to continue . . .
Question 1 : Why is 1 missing here?
int x=0;
srand (time(NULL));
for (int i=0;i <100; i++)
{x =rand ()%9;
if ( (x != 7) || (x != 8))
printf ("%d ",x);
}
Result of print
3 1 2 8 5 6 2 4 8 2 8 3 1 4 8 6 1 6 7 1 0 4 7 4 0 6 4 8 5 8 2 0 1 1 7 8 2 6
7 7
0 3 1 2 1 6 2 4 1 2 1 8 2 0 2 7 8 8 1 6 0 5 3 1 3 7 3 3 6 5 2 1 2 4 7 3 6 6
3 0
4 2 2 1 4 1 7 1 4 4 3 4 8 0 7 1 2 6 4 7
Press any key to continue . . .
Question 2 : I dont want 7 and 8 to be printed. X is not to be 7 or 8.
But why they are still printed?
What is the correct statement to write?
Thank you
Khoon
Can anyone explain what is happening?
int x=0;
srand (time(NULL));
for (int i=0;i <100; i++)
{x =rand ()%9;
if ( x !=( 7||8))
printf ("%d ",x);
}
Result of Print
5 8 7 4 8 3 0 7 2 8 2 7 6 7 5 7 8 3 0 0 6 5 0 4 7 6 5 8 5 2 0 2 0 6 4 8 7 3
2 6
2 3 6 2 3 7 2 5 5 6 3 7 2 3 7 4 4 2 5 6 0 4 5 4 4 5 0 5 6 7 5 3 6 3 2 0 5 0
0 5
7 5 8 6 3 2 2 8 3 6 8
Press any key to continue . . .
Question 1 : Why is 1 missing here?
int x=0;
srand (time(NULL));
for (int i=0;i <100; i++)
{x =rand ()%9;
if ( (x != 7) || (x != 8))
printf ("%d ",x);
}
Result of print
3 1 2 8 5 6 2 4 8 2 8 3 1 4 8 6 1 6 7 1 0 4 7 4 0 6 4 8 5 8 2 0 1 1 7 8 2 6
7 7
0 3 1 2 1 6 2 4 1 2 1 8 2 0 2 7 8 8 1 6 0 5 3 1 3 7 3 3 6 5 2 1 2 4 7 3 6 6
3 0
4 2 2 1 4 1 7 1 4 4 3 4 8 0 7 1 2 6 4 7
Press any key to continue . . .
Question 2 : I dont want 7 and 8 to be printed. X is not to be 7 or 8.
But why they are still printed?
What is the correct statement to write?
Thank you
Khoon