Question

I have a assignment that I'm having trouble with, I have to create a program that...

I have a assignment that I'm having trouble with, I have to create a program that will accept an integer and convert it to binary. I must use an array in the program to build the binary number. Thank you in advance :)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of code:

output:

code:

#include<stdio.h>
int main()
{
int n,r,k,i;
printf("Enter a number: ");
scanf("%d",&n);
int a[20];
k=0;
while(n>0)
{
r=n%2;
a[k++]=r;
n=n/2;
}
printf("Binary Convertion is: ");
for(i=k-1;i>=0;i--)
printf("%d",a[i]);
}

//please upvote.

Add a comment
Know the answer?
Add Answer to:
I have a assignment that I'm having trouble with, I have to create a program that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm using visual studios ASP.net with C# and I'm having trouble doing theses conversions. To convert...

    I'm using visual studios ASP.net with C# and I'm having trouble doing theses conversions. To convert a text date to a DateTime object, use the Convert.ToDateTime method. To get the number of nights, you can subtract the departure date from the arrival date and then use the Days property of the resulting TimeSpan object. To convert a selection in the drop-down list for the number of people to an integer, use the Convert.ToInt32 method.

  • Please help with this function i'm having trouble with: must be written in c++ All of...

    Please help with this function i'm having trouble with: must be written in c++ All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. Your program must not use...

  • Hello everyone! I am working on my assignment for C++ and I'm having a bit of...

    Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...

  • Hey I have this assignment I am having trouble understanding how to interact with the ac...

    Hey I have this assignment I am having trouble understanding how to interact with the ac current in Ohms law. Please show all steps! Thank you! (1 fxii) if Is-(2/30°) A in the circuit below, use phasors and nodal analysis to find ½ IB -j5 Ω 1020 A 6Ω 3Ω V2

  • Please help with this function i'm having trouble with: must be written in c++ All of...

    Please help with this function i'm having trouble with: must be written in c++ All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. Your program must not use...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • I'm having trouble with my program. My goal is to iterate through the array and add...

    I'm having trouble with my program. My goal is to iterate through the array and add only the even values together. When I run this program it hangs and I don't know why.    .text    .globl main main:    lui $16,0x1000    lw $17,0($16) addiu $16, $16, 0    addiu $18, $0, 2    addiu $19, $0, 28    loop: beq $16, $19, exit    div $17, $18    mfhi $13    beq $13, $0, even    addiu $16,...

  • C++ PROGRAMMING Hi! My assignment prompt is below. What I'm having the most trouble understanding is...

    C++ PROGRAMMING Hi! My assignment prompt is below. What I'm having the most trouble understanding is where the shapes are being stored. I'm assuming an array, but I'm not sure how sizing would work. Any help is appreciated, thanks! I have also attached the .h file we must use. Prompt: The goal of HW2 is to implement classes representing shapes. A given program will use this class to create shapes at arbitrary locations in the x-y plane and move them....

  • Hello, I'm having trouble with solving this problem. I have found the bounds and am trying to fin...

    Hello, I'm having trouble with solving this problem. I have found the bounds and am trying to find an equation to solve for it, but am confused. Please help! Thank you in advance! Where S consists of the paraboloid y-z? + z2,0 < y < 1 and the disk x2 + z2 < 1, y-1, and has outward Orientation Consider splitting the surface into its parts S S1 US2 where S1 is the paraboloid and S2 is the disk. Then...

  • I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below....

    I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below. If you could leave comments pointing out where pointers are used it would be much appreciated! ----------------------------------------------------------------------------------------------------------------------------------- Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT