Please Help with For Loop

This is a discussion on Please Help with For Loop within the C Programming forums, part of the General Programming Boards category; I've got four assignments due tomorrow, I did all but one because I'm just so confused. If anyone can help, ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    6

    Please Help with For Loop

    I've got four assignments due tomorrow, I did all but one because I'm just so confused. If anyone can help, it would mean the world to me.

    So here it is,and thank you in advanceb...

    Write a program that will read an integer N and then compute 2 to the power N. You are required to use a for loop.



    In the examples below, what you see in italics is what the computer prints and what you see in boldface is what the user types.


    Example 1

    Enter N: 3

    2 to the power 3 is 2*2*2 = 8


    Example 1

    Enter N: 5

    2 to the power 5 is 2*2*2*2*2 = 32

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So where's your attempt? This has to be one of the simplest loop assignments I've ever seen posted here.


    Quote Originally Posted by kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.

    It appears that you are posting a homework assignment or other project.

    Please don't ask people to do all your work for you, See the announcement on Homework at the top of all forums to see what is acceptable or PM me. Basically people are happy to help, but they're not going to do it all for you.

    Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. If it's something that you absolutely don't understand how it works, like you have no clue how qsort works, then ask a general question about the function and I'm sure someone will explain it. Though they may not give you all of the code for it, but someone will explain the concept.


    On obivous homework questions especially, I like to remind people of the board's ninth guildeline, while this board is very helpful to people, make sure you have your instructor's permission before seeking help on assignments. While people on these boards are more than happy to help, we discourage people from asking for help on graded work without the instructor's permission, and we claim no repsonsibilty for any cheating or honor violations.

    Feel free to PM me with any questions.

    Good Luck,

    Kermi3

    Read and follow the above instructions, and try your post (in the same thread) again.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Post your attempt(s), preferably within code tags: [code][/code].
    Last edited by Dave_Sinkula; 10-19-2005 at 07:25 PM. Reason: Twice! Within hours! Quzah: you need another beer.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    Quote Originally Posted by Dave_Sinkula
    Post your attempt(s), preferably within code tags: [code][/code].
    I don't even know where to start, I really could use some starting help.

    Thanks!

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Example 1

    Enter N: 3
    That looks like a good starting place to me.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by blustrk
    I don't even know where to start, I really could use some starting help.
    I generally start with this:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       return 0;
    }
    Then I start adding code.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    Quote Originally Posted by Dave_Sinkula
    I generally start with this:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       return 0;
    }
    Then I start adding code.

    What about the for loop?

  8. #8
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by blustrk
    What about the for loop?
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       for(;;);
       return 0;
    }
    Modify to your heart's content. It might help if you read this.
    Last edited by pianorain; 10-20-2005 at 11:57 AM.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by blustrk
    Quote Originally Posted by Dave_Sinkula
    I generally start with this:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       return 0;
    }
    Then I start adding code.
    What about the for loop?
    Yup, that'd be one of the first things I'd add.
    Last edited by Dave_Sinkula; 10-20-2005 at 12:51 PM. Reason: Fixed quote.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Seriously consider this following statement, as it will save you time in the long run:

    If you aren't going to even try, don't bother. All you're doing is wasting everyone's time with your "do it for me" mentality. If you can't figure out this simple problem, stop trying to program. You don't want to bad enough. This is a ........ing easy problem. I hate to even use the word "problem", because it doesn't qualify as one.

    I mean, you aren't making any attempt at all. If you have that little self esteem, where you can't post your code attempt, then get off of a public message board. If not esteem, then you're just too damn lazy. Too lazy to make any of the most minute attempts at this problem. If you're not lazy, then unfortunately for you, you're just too stupid. Too stupid to read a book or tutorial covering the simplest of concepts.

    If it isn't any of those, put up or shut up, because you're wasting our time.


    Quzah.
    Last edited by quzah; 10-20-2005 at 12:47 PM.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    >>I've got four assignments due tomorrow, I did all but one because I'm just so confused. If anyone can help, it would mean the world to me.
    Making the platform hmm .Nice way of asking others to do things for you.Anyways what other questions were?i guess adding two 1.integers 2.two doubles 3.floats
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21