ninuzz
26-01-2011, 17:29
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{int i,j,nx,ny;
char scacchiera[][5]={{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '}};
srand(time(NULL));
for(i=1; i<=6; i++)
{nx=rand()%5;
ny=rand()%5;
scacchiera[nx][ny]='x';
}
for(i=0; i<5; i++){
for(j=0; j<5; j++)
printf("%c",scacchiera[i][j]);
printf("\n");}
voglio posizionare 6 'x' sulla scacchiera...ma dalla funzione rand() a volte mi escono 5 e a volte 6 'x'...?
:help: grazie in anticipo per l'aiuto
#include <stdlib.h>
#include <time.h>
int main()
{int i,j,nx,ny;
char scacchiera[][5]={{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' '}};
srand(time(NULL));
for(i=1; i<=6; i++)
{nx=rand()%5;
ny=rand()%5;
scacchiera[nx][ny]='x';
}
for(i=0; i<5; i++){
for(j=0; j<5; j++)
printf("%c",scacchiera[i][j]);
printf("\n");}
voglio posizionare 6 'x' sulla scacchiera...ma dalla funzione rand() a volte mi escono 5 e a volte 6 'x'...?
:help: grazie in anticipo per l'aiuto