-
Notifications
You must be signed in to change notification settings - Fork 0
/
ques8.c
42 lines (31 loc) · 831 Bytes
/
ques8.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
#include <stdio.h>
int ques8(int x) {
// if x > 0, y = 0, if x < 0, y = -1
int y = x >> 31;
// z will always return 1
int z = !!x;
// returns 1 if x > 0, returns -1 if x < 0, and 0 for x = 0.
return y | z;
}
int ans8(int x){
if (x<0) return -1;
else if(x==0) return 0;
else return 1;
}
int main(){
int param;
printf("Enter a number to be manipulated: \n");
scanf("%d", ¶m);
if (ques8(param) == 1)
printf("The number you entered was positive.\n");
else if (ques8(param) == -1)
printf("The number you entered was negative\n");
else
printf("You entered 0.\n");
if (ans8(param) == 1)
printf("The number you entered was positive\n");
else if(ans8(param) == -1)
printf("The number you entered was negative\n");
else
printf("You entered 0.\n");
}