-
Notifications
You must be signed in to change notification settings - Fork 0
/
kings.c
56 lines (52 loc) · 1.85 KB
/
kings.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
/*************************************************************************
* The Problem Solved Kings in C *
* ---------------------------------------------------------------------- *
* *
* POC: $ ./kings <number of rows> <number of columns> *
* Help: $ ./kings -h *
* *
* Autor: Elton Fonseca *
* http://www.fb.com/elton.junior6 *
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
int king, i, j, rows, columns;
void help();
if(argv[2] == NULL || argc < 2 || argc > 3)
{
printf("Error! for more informations, use: -h\n");
}
else if(strcmp(argv[1], "-h") == 0)
{
help();
}
else
{
rows = atoi(argv[1]);
columns = atoi(argv[2]);
i = 1;
while(i <= rows)
{
j = 1;
while(j <= columns)
{
king++;
j += 2;
}
i += 2;
}
printf("Kings: %d\n", king);
}
}
void help()
{
printf("+---------------------------------------------------------+\n");
printf("+ The Problem Solved Kings in C +\n");
printf("+ +\n");
printf("+ Use: $ ./kings <number of rows> <number of columns> +\n");
printf("+---------------------------------------------------------+\n");
}