+ 2
Bitwise Value in C Lang
in C language bitwise value what is the difference between && ,&,||,| ?
2 odpowiedzi
+ 3
&& and || are logical operator, used for calculate 2 boolean value using logic gate
ex. (a==b)&&(!boolean)
& and | are bitwise operator, its used for calculate 2 value, using its binary form.
ex 1|2
1: 0001
2: 0010
-------------- OR
3: 0011
0
#include <stdio.h>
#define MAX 15
int missing_number_array(int [],int);
int main()
{
int a[MAX], num, i, n;
printf("enter the range of array\n");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("enter a[%d]element into the array:", i);
scanf("%d", &a[i]);
}
num = missing_number_array(a, n);
printf("The missing number -> %d\n", num);
}
/* To find the missing number in array */
int missing_number_array(int a[], int n)
{
int i;
int s1 = 0;
int s2 = 0;
for (i = 0; i < n; i++)
s1 = s1 ^ a[i];
for (i = 1; i <= n + 1; i++)
s2 = s2 ^ i;
return (s1 ^ s2);
}