Variable declarations in while loop conditions are also C++-only.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
enum { maxval = 9 };
printf("Here's a handful of \"random\" numbers from 1 to %d:\n", maxval);
srand((unsigned)time(NULL));
while (const int n = rand() % (maxval + 1)) printf("%d\n", n);
puts("Done.");
}
|
run
| edit
| history
| help
|
0
|
|
|