Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a C program, create a program that: prompts the user for three positive integ

ID: 3717347 • Letter: I

Question

In a C program, create a program that:

prompts the user for three positive integers, a, b, and c. Each integer should be stored as an unsigned short int. To obtain an unsigned short int, "90hu" should be used instead of "90i" with the scanf function call. . the bits of each integer should be printed to the screen. The function printbits from class lab will be helpful here. .Let a, b, c each represent the ith bit of a, b, and c respectively. Find the integer x such that the ith bit of x (denoted by x) is 1 if and only if at least 2 of ai, b, and ci are 1. That is, xi 1 if two of the three bits ai bi, and ci are 1 and x0 otherwise (see sample program below) Print the integer x to the command line as well as print the bits of x to the screen Sample program: Enter a: 248 Enter b: 204 Enter c: 17e Bitwise representation of a: Bitwise representation of b: 000e000110 0110e Bitwise representation of c: 00000001010101 e x: 232 Bitwise representation of x: e ee e 0 0 0 1 1 1 0 1 0 e e

Explanation / Answer

#include<stdio.h>
int main()
{
int n; // getting the number
scanf("%d",&n);
while(n--)
{
unsigned short int a; // declaring the unsigned short int
scanf("%hu", &a);
  
int dig;
int b[100],k=0;
while(a!=0)
{
dig=a%2;// performing modulo operator to get the individual digit and store it in the array
  

a=a/2;
b[k]=dig;
k++;
}printf("the bit wise representation is: ");
for(int i=k-1;i>=0;i--)
{
printf("%d",b[i]);// print the array elements in the reverse order
}
printf(" ");
}
return 0;
}

input:

3

240

204

170

output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote