-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanf_triangle.c
More file actions
49 lines (40 loc) · 850 Bytes
/
scanf_triangle.c
File metadata and controls
49 lines (40 loc) · 850 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define X_NAME "first"
#define Y_NAME "second"
#define Z_NAME "hipo"
#define MAX_LEN (10)
#define FMT_LEN (20)
#define INT_LEN (5)
int main()
{
int x = 0;
int y = 0;
int z = 0;
char fmtstr[INT_LEN + FMT_LEN] = {0};
sprintf(fmtstr, " %%%d[" X_NAME Y_NAME Z_NAME "] = %%d", MAX_LEN);
printf("Input:\n");
int tmpval = 0;
char tmpstr[MAX_LEN] = {0};
for (int i = 0; i < 3; ++i) {
if (scanf(fmtstr, tmpstr, &tmpval) < 2) {
printf("Incorrect input\n");
exit(1);
}
if (strcmp(tmpstr, X_NAME) == 0)
x = tmpval;
else if (strcmp(tmpstr, Y_NAME) == 0)
y = tmpval;
else if (strcmp(tmpstr, Z_NAME) == 0)
z = tmpval;
else {
printf("Incorrect input\n");
exit(1);
}
}
if (x * x + y * y == z * z)
printf("Yes\n");
else
printf("No\n");
}