Im trying to find uniqeness for my program that I have and I dont know how to write it...
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int gen( int letter )
{
int x = rand()% 14 + 1 + 15* letter;
return x;
}
int main()
{
int i;
int j;
int A[5][5];
int letter;
int unique;
FILE *card;
srand(time(0));
card = fopen("card", "w");
for (i = 0; i %26lt; 5; ++i)
{
for(j = 0; j %26lt; 5; ++j)
{
A[i][j] = gen(i);
}
}
A[2][2] = 0;
printf("B\tI\tN\tG\tO\t\n");
fprintf(card,"B\tI\tN\tG\tO\t\n");
for (i = 0; i %26lt; 5; ++i)
{ printf("%d\t%d\t%d\t%d\t%d\n", A[0][i], A[1][i], A[2][i], A[3][i], A[4][i]);
fprintf(card, "%d\t%d\t%d\t%d\t%d\n", A[0][i], A[1][i], A[2][i], A[3][i], A[4][i]);
}
fclose(card);
return 0;
}
C Programming?
what is your problem here? is it about getting different random values?
if so, then time() returns a time_t (time type); you need to convert it to an unsigned int then pass to srand().
baby breath
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment