-
-
Save soul0592/5899355 to your computer and use it in GitHub Desktop.
Generador de números pseudoaleatorios.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
void aleatorio(int largo,int renglon) | |
{ | |
FILE *a; | |
int i,j,random; | |
int uno = 0, cero = 0; | |
a = fopen("keyc.dat", "w"); | |
srand(time(NULL)); | |
for(i = 0; i < renglon; i++) | |
{ | |
for(j = 0; j < largo; j++) | |
{ | |
random = rand() % 2; | |
fprintf(a,"%d", random); | |
if(random == 1) | |
uno++; | |
else | |
cero++; | |
} | |
fprintf(a,"\n"); | |
} | |
fprintf(a,"\nCeros: %d\nUnos: %d",cero,uno); | |
fclose(a); | |
} | |
int main (int argc, char *argv[]) | |
{ | |
int largo = atoi(argv[1]); | |
int renglon = atoi(argv[2]); | |
aleatorio(largo,renglon); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment