Bitwise And
Symbol used is ^
Practice Problem
https://www.codechef.com/problems/MISSP
#include <stdio.h>
int main()
{
int t, n, m, b;
scanf ("%d\n", &t);
while (t--)
{
b = 0;
scanf("%d\n", &n);
while (n--)
{
scanf("%d\n", &m);
b ^= m;
}
printf("%d\n", b);
}
return 0;
}
Bitwise <<
- #include<stdio.h>
- int main()
- {
- int n;
- printf("Enter an integer\n");
- scanf("%d",&n);
- if ( n & 1 == 1 )
- printf("Odd\n");
- else
- printf("Even\n");
- return 0;
- }
Bitwise XOR
Symbol used is ^
#include <stdio.h> main() { int x=1,y=3; if(x ^ y) printf("x is not equal to y"); else printf("x is equal to y"); }
Practice Problem
https://www.codechef.com/problems/MISSP
Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which all dolls have paired.One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!
Help chef find which type of doll is missing..
#include <stdio.h>
int main()
{
int t, n, m, b;
scanf ("%d\n", &t);
while (t--)
{
b = 0;
scanf("%d\n", &n);
while (n--)
{
scanf("%d\n", &m);
b ^= m;
}
printf("%d\n", b);
}
return 0;
}
Bitwise <<
No comments:
Post a Comment