write a program that takes in a positive integer as input, and output a string of 1's and 0's representing the integer in binary. for an integer x; the algothm is as long as x is greater than 0 output x % (remainder is either 0 or 1 . x=x/2 in coral language

Answers

Answer 1

Answer: Provided in the explanation section

Explanation:

The full questions says:

write a program that takes in a positive integer as input, and output a string of 1's and 0's representing the integer in binary. for an integer x; the algothm is as long as x is greater than 0 output x % (remainder is either 0 or 1 . x=x/2 in coral language. Note: The above algorithm outputs the 0's and 1's in reverse order.

Ex: If the input is:

6

the output is:

011

CODE:

#include <stdio.h>

int main() {

   int n;

   scanf("%d", &n);

   while (n > 0) {

       printf("%d", n % 2);

       n /= 2;

   }

   printf("\n");

   return 0;

}

2

#include <stdio.h>

int main() {

   int n;

   scanf("%d", &n);

   while (n > 0) {

       printf("%d", n % 2);

       n /= 2;

   }

   return 0;

}

cheers i hope this helped !!


Related Questions

Write a script called checkLetter.sh Review Greeting.sh for an example. Use a read statement and ask user to "Enter A, B, or C: "

If user types A, echo "You entered A"
If user types B, echo " You entered B"
If user types C, echo " You entered C"
Use the case structure to test the user’s string.
If user types any letter from lower case ‘a through z’ or upper case ‘D through Z’, echo "You did not enter A, B, or C".

Answers

Answer:

The code is given as below: The input and output is as given for one case.

Explanation:

echo -e "Enter A, B or C : \c" #Printing the line on the screen

read -rN 1 test #read the character in the variable test

echo

case $test in #Setting up the case structure for variable test

[[:lower:]] ) #checking all lower case letters

echo You did not enter A, B or C;;

[D-Z] ) #checking upper case letters from D to Z

echo You did not enter A, B or C;;

A ) #Condition to check A

echo You entered A;;

B ) #Condition to check B

echo You entered B;;

C ) #Condition to check C

echo You entered C;;

esac #Exiting the case structure

Other Questions
A bookstore charges $4 for shipping, no matter how many books you buy. Irena makes a graph showing the shipping cost for I to 5 books. She claims that the points she graphed lie on a line. Does her statement make sense? Explain Formula for drip rate URGENT The number of counties in state A and the number of counties in state B are consecutive even integers whose sum is 158. If state A has more counties than state B, how many counties does each state have? A car starts 10 m north of a reference point. It moves at a constant velocity over the next 5 s, reaching a position of 10 m south of the reference point. What is the car's average velocity? Who is following the law when it comes to protecting investors funds? A number is multiplied by 5. If 5 is added to the product, you get 10. What is the number? Which best describes the role the applicants can fill in the company? Applicants 1 and 3 are best suited to work in network systems, while Applicant 2 could work in programming, information support, or interactive media. Applicants 2 and 3 are best suited to work in network systems, while Applicant 1 could work in programming, information support, or interactive media. Applicant 1 is best suited to work in network systems, while Applicants 2 and 3 could work in programming, information support, or interactive media. Applicant 3 is best suited to work in network systems, while Applicants 2 and 3 could work in programming, information support, or interactive media. Joey and Nolan are each solving the equation 13x - 42 = 18 - 7x. Joey's first step was to rewrite the equation as 20x - 42 = 18 while Nolan's first step was to rewrite the equation as 13x = 60 - 7x. Who is correctly applying the addition property of equality in the first step of his work? A. Only Joey B. Only Nolan C. Both Joey and Nolan D. Neither Joey nor Nolan what is 6(1-10p)-7 jfghhdddcv HELP ASAP!There is a lever with 5 m long. The fulcrum is 2 m from the right end. Each end hangs a box. The whole system is in balance. If the box hung to the right end is 12 kg, then what is the mass of the box hung to the left end? A cylinder with a base diameter of x units has a volume ofcubic unitsWhich statements about the cylinderoptions.The radius of the cylinder is 2x units.The area of the cylinder's base is ax? square units.The area of the cylinder's base is nx square units.The height of the cylinder is 2x units.The height of the cylinder is 4x units. Which event in Earth's history most directly allowed life to exist on land?Earth's temperatures increased, causing widespread evaporation.Earth collided with a large object, forming the moon.Single-celled organisms released oxygen into the air when they photosynthesized.Single-celled organisms absorbed harmful gases from the air when they first formed. In what ways did European colonizers expand their colonies? What is the value of log6255? Find the missing factor A spaceship travels toward the Earth at a speed of 0.97c. The occupants of the ship are standing with their torsos parallel to the direction of travel. According to Earth observers, they are about 0.50 m tall and 0.50 m wide. Calculate what the occupants height and width according to the others on the spaceship? Tommy can exchange 8 euros for 11 dollars.At this rate, how many dollars can Tommy get with 12 euros? The science club is experiencing a growth in membership. On average, they areseeing 2 new members sign up each week. If they started with 10 members whichfunction, S(x), represents the number of members in the science club after x weeks? a family of 8 has 3 of them being males what proportion of the family is female Why is co2 used in fire extinguishers ?