Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Programming homework help

c nested loop

  • Please log in to reply
16 replies to this topic

#13 iskaksen

iskaksen

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C
  • Learning:C

Posted 19 September 2012 - 04:46 AM

I have the same tasks(I presume we even go to the same class, OP) And I've solved all the tasks up to the 9th... The book is so general that it hurts and I can't seem to find some functions that help me shift between binary and 10-digit.
There seem to be some problems with compiling anything but main, but I'm going to ignore that for the sake of braintwisting.
Any hints on the 9th task guys?
  • 0

#14 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 19 September 2012 - 04:55 AM

My answers so far is this.

I know most, if not all answers here is wrong. But I hope to get an input of what i have done wrong, and maybe explain why my answer is wrong.

Problem 1
3 is the decimal number, ‘3’ Refers to the ASCII value of 3, and

...


The first part is correct. I don't think that's what they are going for on the second part. I think they are really asking what is the difference between '3' and "3", but the variable (3 in this case) can be replaced with anything. There is a distinct difference between single quotes and double quotes.
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#15 iskaksen

iskaksen

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C
  • Learning:C

Posted 20 September 2012 - 11:43 AM

nobody got no clues about the last task?
  • 0

#16 Smilex

Smilex

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 76 posts
  • Location:Faroe Islands
  • Programming Language:C, C++, PHP, Python, JavaScript, Lua, Others
  • Learning:Objective-C, PHP, Python, Assembly, Bash

Posted 20 September 2012 - 04:18 PM

I'm actually a bit curious about problem 9 myself. Is counting the times you have to shift the value to the right, to get it to be equal to one, the correct way?
  • 0

#17 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 20 September 2012 - 07:29 PM

Yes, but you have to be careful. The first 1 you encounter is not likely to be the right bit. Look at the example number - if you return the position of the first bit set to 1, you're gonna be wrong. You can do it one of two ways

1) Start at the highest bit and shift right until you hit the first 1, then return that.
2) Start at the lowest bit and shift left until you hit the last 1, then return that.

Make sure you handle the case where n = 0.
  • 1

sudo rm -rf / && echo $'Sanitize your inputs!'






Also tagged with one or more of these keywords: c, nested loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download