-
Notifications
You must be signed in to change notification settings - Fork 0
/
ques14.c
50 lines (37 loc) · 790 Bytes
/
ques14.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int ques14(int x) {
int result = 0;
int i;
for (i = 0; i < 32; i++)
result ^= (x >> i) & 0x1;
return result;
}
int ans14(int x){
int count = 0;
while(x){
count += x&1;
x >>=1;
}
if (count % 2 == 1) return 1;
else return 0;
}
int main(){
int param;
printf("Enter a number to be manipulated: \n");
scanf("%d", ¶m);
if (ques14(param) == 1){
printf("There is an odd number of 1's in the string.\n");
}
else{
printf("There is an even number of 1's in the string.\n");
}
if (ans14(param) == 1){
printf("There is an odd number of 1's in the string.\n");
}
else{
printf("There is an even number of 1's in the string.\n");
}
}