-
Notifications
You must be signed in to change notification settings - Fork 0
/
gera.c
54 lines (42 loc) · 746 Bytes
/
gera.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX 100
void crescente(int n){
int i;
for(i=1; i<=n; i++){
printf("%d\n", i);
}
}
void descrescente(int n){
int i;
for(i=n; i>0; i--){
printf("%d\n", i);
}
}
void aleatorio(int n){
int i;
srand(time(NULL));
for(i=0; i<n; i++){
printf("%d\n", rand() % MAX);
}
}
int main(int argc, char* argv []){
int n, tipo;
if(argc != 3){
printf("Erro, número de argumentos inválidos!");
exit(1);
}
//obtem o numero de elementos a serem gerados
n = atoi(argv[2]);
if(strcmp(argv[1], "-a")==0)
aleatorio(n);
else if(strcmp(argv[1], "-c")==0){
crescente(n);
}
else if (strcmp(argv[1], "-d")==0){
descrescente(n);
}
return 0;
}