Created
March 16, 2023 16:17
-
-
Save folivetti/ee2e3acc6779ff331391e1d78f3fcd9f to your computer and use it in GitHub Desktop.
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> | |
int main(int argc, char *argv[]) { | |
int n, min, max, x, i; | |
time_t t; | |
srand((unsigned) time(&t)); | |
if (argc < 3) { | |
printf("Uso: ./gerar n min max"); | |
return -1; | |
} | |
n = atoi(argv[1]); | |
min = atoi(argv[2]); | |
max = atoi(argv[3]); | |
for (i=0; i<n; i++) { | |
x = min + (int)((double)rand() / ((double)RAND_MAX / (max - min + 1) + 1)); | |
printf("%d", x); | |
if (i < n-1) printf(" "); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment