i have a question about c programming.can you help for the solution.thank you . i just use C not C++
**Question: **
Write a C program for a binary notation simulator for positive integer numbers. Your program will ask and get positive integer numbers from user. Program will stop asking new numbers if 0 is input. It will display the binary representation of the input number and the minimum number of digits required to represent that number as given in the sample run.
Sample Run: (Italic and bold letters indicate the user input)
Enter a positive integer: -5
Enter a positive integer: -3
Enter a positive integer: 5
It is 101. At least 3 digits required.
Enter a positive integer: -2
Enter a positive integer: 7
It is 111. At least 3 digits required.
Enter a positive integer: 0
Stop… Bye…
Perhaps you could walk us through your strategy to design this project, and we could help you out. Here are some questions to think about:
How are you going to get the binary value of an integer?
How are you going to handle bad input (i.e. negative numbers, and the 0 to escape)?
How are you going to handle having a minimum of three output digits?
While number>0
push a bit equal to (number mod 2) onto the end of the binary number
divide (number-(number mod 2)) by 2
end while
that should get you started, as a couple of hints, if all you are doing is printing out the number you may not need the array, also c truncates numbers when you do integer math, this simplifies the loop slightly.
See what you can figure out and feel free to ask for help
yes you are right.but i’m in the beginning of the programming because i newly started writing some easy programs.i’m only a highschool student and we are not learning c programming lessons now.i write the topic as this was a homework to call your attention…and i have a question waiting for an answer.you are all system engineers or computer software engineers and i think you can give 2 or 3 minutes to my question.i would be very grateful if you can help me on writing the program by steps…
Stop reading (at least for these purposes) at “Hexadecimal, Octal, Bits, Bytes and Words.”, and skip mention of negative numbers and fractions. The article gives a good introduction, and even has a couple of self-test questions.
I encourage you to not go to Wikipedia, their article is a good reference but a poor tutorial.
You should not expect others to do your homework for you.
you are all system engineers or computer software engineers
No, we’re all part of a program called FIRST. Some of us are engineers, and a few of us are professional computer programmers, but the majority of the people reading your post are high school students.
and i think you can give 2 or 3 minutes to my question.i would be very grateful if you can help me on writing the program by steps…
It would be easy to spend a few minutes to write a program to satisfy your assignment. That’s not the way it works around here, though.
JamesBrown and garyk have given good advice. Again, if you have specific questions about how to do something, you’ll find us ready to answer them.
I think you’re missing the point of those that posted above. Yes, there are people on these boards that could write your program for you in less time than it would take to state the problem, but how is that going to help you as a student? When it comes to learning how to program, I guarantee you that the best way to learn is to struggle through the homework and ask appropriate questions to aid your learning.
The main problem that I see with your approach is that you’re looking at the problem as a whole and trying to solve it as a whole. If you were given a large algebra problem like 2x + (x - 4) / x = 3y - x + 2 and were told to solve for y when x was 4, how would you do it? Probably in steps right?
You should treat your assignment the same way. So what steps/things do you have to do to complete your assignment?
Get an input from the user
Determine if the number can be processed
If the number can be processed, process it
3a Convert the number to binary
3b Print out the result
If the number is 0, print then exit your program
The best advice that I can give when you’re given an overwhelming problem is to write a little bit, test, fix what’s broken, retest, and repeat until the whole problem is done.
Try writing a program that first does step 1. Then add on step 2 (you can use prints to let you know whether the number will be processed or not). Then add step 4 (skipping 3 for now). Then add steps 3 and 3b. Notice that I left the hard stuff (binary conversion) until the end. Once your program has the framework to do everything but the binary conversion, add that in.
It really isn’t as hard as you think it is. Think through the problem piece by piece and I’m sure that you’ll be able to work through it.
If you run into problems, ask specific questions other than “this is my problem, please give me the answer” and I’m sure that you will be more likely to get the appropriate help.
i don’t need to know your advertisements or whatever you are working in just ask a question and reading some blank messages…
so thank you dave for your kind message.i can write the program but one step is required.
you said
3a Convert the number to binary
in your message.and i don’t know how to find the binary of the number on a program.i can do the others bur the main problem is this part because i don’t know it.i want to say it again this is not a homework or assignment because in highschool there is no lesson about programming.i will see c programming on the college next year and i started learning it 3 months ago.i’m new at this and i’m saying that i need help but some of you writing me messages with no knowledge in them…
one step is needed dave waiting your message…thank you…
Often the best way to answer a question is to first ask a few in return. Before anyone can help you, I think we need to know:
Do you know what binary numbers are?
Here’s a quick warning: Your profile says you’re from Turkey, which in itself is not a problem at all. Understand that in North America we often have different perspectives on what “learning” is. I say this having had family and friends educated overseas, where “learning” centres around memorizing and repetition. Not so much emphasis is put on understanding.
You will not find anyone here who will write your program for you.
You will find dozens willing to teach you and direct you to source where you will 100% learn and understand how to write your own program.
That’s approximately infinitely more valuable in my opinion.
I outlined an algorithm to find binary numbers in my post above, do you understand what i said to do? If you don’t what do you need more advice on. If you understood what i said then where are you getting stuck.
Honestly from what you have said the only thing that would seem to satisfy what you are looking for would be for us to write the program for you which quite frankly i am not going to do. All we ask is that you ask more specific questions.
yes i know the binary numbers but don’t know how to write on C.
Do you know how to write binary numbers in a C program ?
i don’t know where are you from but think that toronto is not your real town.i don’t need your education knowledge or your learning perspective.and i think in your hometown you don’t know anythink about helping…but as an engineer you should know this ethic i think.
thank you for your genious decisions and opinions but you answered my question with another question and that is your answer i think lol
Toronto is indeed my hometown, and I have been consistently recognized as one of the best engineers in my profession, one of the best business people in my industry, one of the best mentors in FIRST, and one of the best teachers in both computer science and mathematics in my area.
I challenge my students, colleagues, and peers at every opportunity, and will now challenge you in the same way.
I actually don’t believe you know binary numbers.
Prove me wrong.
Take the number 188, and show us all, step by step, how you would convert it into binary representation.
Whether you realize it or not, if you can successfully do this, you’ll end up getting the help you so desperately need with your assignment. But only after you do this can the community here help you code each of your steps into C.
you look like not a toronto people korean or chinese or like that…you are the king congratulations or you think that you are the best,nice for you.you said you have challanged with your students what a genius man you are challenging with students huh!
I’m glad that my post helped you, but from this point on I will be silent in this thread. The disrespect and immaturity that you have shown clearly demonstrates that you have more to learn than C programming. Slimbo made a valid point and you have chosen to take that as an attack for whatever reason.
either you failed to understand what jones meant or you seriously need to realize something: We are completely willing to help you, but instead of just telling you what to do we want you to learn the method behind it so that you can better yourself and your programming.
As the proverb says:
“Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.”