Sep 26, 2002 #2 bluedemus Programmer Sep 24, 2002 21 US This is sample code to print out a 5 by 6 array of lotto numbers...I'm not sure if this is what you need... #include <stdlib.h> #include <stdio.h> #include <time.h> #include <iostream.h> void GenerateNumbers( int lotto[][6] ); main() { int lotto[5][6], r, c; srand(( unsigned ) time(NULL )); GenerateNumbers( lotto ); for ( r=0; r < 5; r++ ) { for ( c=0; c<6; c++ ) { cout << lotto[r][c] << " "; } cout << "\n\n"; } cout << "\n\n"; } void GenerateNumbers(int lotto[][6] ) { int num, r, c; for ( r=0; r < 5; r++ ) { for ( c=0; c<6; c++ ) { num = rand() % 47; lotto[r][c] = num; } } } Upvote 0 Downvote
This is sample code to print out a 5 by 6 array of lotto numbers...I'm not sure if this is what you need... #include <stdlib.h> #include <stdio.h> #include <time.h> #include <iostream.h> void GenerateNumbers( int lotto[][6] ); main() { int lotto[5][6], r, c; srand(( unsigned ) time(NULL )); GenerateNumbers( lotto ); for ( r=0; r < 5; r++ ) { for ( c=0; c<6; c++ ) { cout << lotto[r][c] << " "; } cout << "\n\n"; } cout << "\n\n"; } void GenerateNumbers(int lotto[][6] ) { int num, r, c; for ( r=0; r < 5; r++ ) { for ( c=0; c<6; c++ ) { num = rand() % 47; lotto[r][c] = num; } } }
Oct 11, 2002 #3 pankajkumar Programmer Mar 14, 2001 90 IN Use the statements like fprintf or file writing to print in files Upvote 0 Downvote
Oct 11, 2002 #4 pankajkumar Programmer Mar 14, 2001 90 IN Better use it #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> int main(int argc, char* argv[]) { int i; FILE *fp; fp=fopen("c:\\newtext.txt","w+" /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ for( i = 0; i < 10;i++ ) { char szTemp[64]; printf( " %6d\n", rand() ); _itoa(rand(),szTemp,10); strcat(szTemp," " fputs(szTemp,fp); } fclose(fp); return 0; } Upvote 0 Downvote
Better use it #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> int main(int argc, char* argv[]) { int i; FILE *fp; fp=fopen("c:\\newtext.txt","w+" /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ for( i = 0; i < 10;i++ ) { char szTemp[64]; printf( " %6d\n", rand() ); _itoa(rand(),szTemp,10); strcat(szTemp," " fputs(szTemp,fp); } fclose(fp); return 0; }