-
Notifications
You must be signed in to change notification settings - Fork 0
/
4 Validating operators.c
35 lines (33 loc) · 1.19 KB
/
4 Validating operators.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
#include <stdio.h>
#include <string.h>
int main() {
char s[100];
printf("Enter a string: ");
gets(s);
int n = strlen(s);
if (n == 1) {
if (s[0] == '+' || s[0] == '-' || s[0] == '/' || s[0] == '*' ||
s[0] == '=' || s[0] == '%' || s[0] == '!' || s[0] == '|' ||
s[0] == '^' || s[0] == '&' || s[0] == '>' || s[0] == '<'
) printf("This is an operator\n");
else printf("This is not an operator\n");
}
else if (n == 2) {
if ((s[0] == '+' && (s[1] == '=' || s[1] == '+')) ||
(s[0] == '-' && (s[1] == '=' || s[1] == '-')) ||
(s[0] == '*' && s[1] == '=') ||
(s[0] == '/' && s[1] == '=') ||
(s[0] == '%' && s[1] == '=') ||
(s[0] == '<' && (s[1] == '<' || s[1] == '=')) ||
(s[0] == '>' && (s[1] == '>' || s[1] == '=')) ||
(s[0] == '!' && s[1] == '=') ||
(s[0] == '&' && s[1] == '&') ||
(s[0] == '|' && s[1] == '|')
) printf("This is an operator\n");
else printf("This is not an operator\n");
}
else {
printf("This is not an operator\n");
}
return 0;
}