Question

In: Computer Science

Write c code to determine if a binary number is even or odd. If it is...

Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.

Solutions

Expert Solution

Code:

#include<stdio.h>
int main()
{
   int bin;
   /*Here we declared a integer*/
   printf("Enter a binary number: ");
   scanf("%d",&bin);
   /*Here we read the binary number from the user*/
   if(bin%10==1)
   {
       printf("%d",1);
   }
   if(bin%10==0)
   {
       printf("%d",0);
   }
   /*
   if the last bit is 1 then it is odd
   if the last bit is 0 then it is even*/
}

Output:

Indentation:


Related Solutions

Question1. (lesson 2) In the following code we determine a number if its even or odd....
Question1. (lesson 2) In the following code we determine a number if its even or odd. Explain what logic is used for that?    section .text    global _start            ;must be declared for using gcc        _start:                     ;tell linker entry point    mov   ax,   8h           ;getting 8 in the ax    and   ax, 1              ;and ax with 1    jz    evnn    mov   eax, 4             ;system call number (sys_write)    mov   ebx, 1             ;file descriptor (stdout)    mov   ecx, odd_msg       ;message...
determine whether the given function is even, odd, or neither. Please write a code in MatLab...
determine whether the given function is even, odd, or neither. Please write a code in MatLab to solve this problem below: 1.f(x) = sin 3x please only use Matlab to solve this problem
Develop a C++ function to find the number of even and odd integers in a given...
Develop a C++ function to find the number of even and odd integers in a given array of integers Pass in an array of integers Pass in the size of the array of integers Pass in a reference parameter for the number of even values Pass in a reference parameter for the number of odd values The function doesn't return anything Develop a C++ program to test your function
Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number...
Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number of 1s or an odd number of 0s
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number....
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number. The main function is given: int main(){     int number;     cout << "Check number input: ";     cin >> number;     cout << "The input number " << number << " is " << checkEvenOrOdd(number) << endl;     return 0; } simple c++ code please
(IN C) Write the code to manage a Binary Tree. Each node in the binary tree...
(IN C) Write the code to manage a Binary Tree. Each node in the binary tree includes an integer value and string. The binary tree is sorted by the integer value. The functions include: • Insert into the binary tree. This function will take in as parameters: the root of the tree, the integer value, and the string. Note that this function requires you to create the node. • Find a node by integer value: This function takes in two...
Prove that every natural number is odd or even.
Prove that every natural number is odd or even.
write code to count the number of odd integers in an array of 100 random integers...
write code to count the number of odd integers in an array of 100 random integers in the range [0,99].
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The function will have one int 1D array n and one int size as parameters. The function will display all the values of n on one line. Function #2 Write the function AverageEvenOdd. The function will have one int 1D array n and one int size as parameters. The size of the array is given by the parameter int size. Therefore, the function should work...
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT