-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabuada.c
65 lines (57 loc) · 1.09 KB
/
tabuada.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
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
#define buffer_size 256
bool check_input_isvalid(const char *arr)
{
for (int index = 0; arr[index] != '\0'; index++)
{
if (arr[index] < '0' || arr[index] > '9')
{
return false;
}
}
return true;
}
void print_sequence(int number)
{
for (int i = 1; i <= 10; i++)
{
printf("%d*%d = %d\n", number, i, (number * i));
}
}
void print_tabuada(int limit)
{
for (int index = 1; index <= limit; index++)
{
puts("===========================");
printf("A tabuada do numero %d é:\n", index);
print_sequence(index);
}
}
int main(int argc, char const *argv[])
{
if (argc == 1)
{
puts("Falta passar os parâmetros!");
return EXIT_FAILURE;
}
if (check_input_isvalid(argv[1]))
{
print_tabuada(atoi(argv[1]));
return EXIT_SUCCESS;
}
char buffer[buffer_size];
while (true)
{
printf("Digite um numero:");
scanf("%s", buffer);
if (check_input_isvalid(buffer))
{
print_tabuada(atoi(buffer));
break;
}
}
return EXIT_SUCCESS;
}