I am trying to draw 10 pseudo random numbers form -10 to 10 and then print them. Unfortunately the amount of numbers isn't 10 - sometimes it's 8, 9, 11 etc. I don't understand why, can you tell me what is wrong in this code?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define n 10
int main()
{
int tab[n];
int i;
srand(time(0));
for(i=0;i<n;i++)
{
tab[n] =(rand()%20)-10;
printf("%3d",tab[n]);
}
return 0;
}
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire