for loops q

This is a discussion on for loops q within the C Programming forums, part of the General Programming Boards category; Hi Sorry about my english I have a for loop written like this. for(i=0; x>=y; i++){ sum = (z - ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    for loops q

    Hi
    Sorry about my english

    I have a for loop written like this.
    for(i=0; x>=y; i++){
    sum = (z - x) / 10;
    x = x + sum;
    printf("Number. %d\n",i)

    The outcome is like this.
    Number. 0
    Number. 1
    Number. 2
    Number. 3
    Number. 4
    Number. 5
    Number. 6
    Number. 7
    Number. 8
    Number. 9
    Number. 10
    Number. 11

    The problem is that i only want it to show the last number.. Number 11 in this case. How do i do that?

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    Code:
    for(i=0; x>=y; i++){
         sum = (z - x) / 10;
         x = x + sum;
    }
    printf("Number. %d\n",i)
    you need to have the print method outside of the loop

    and wow, i actually helped someone who is more noob than me

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    2
    thanks alot..!

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by skyt View Post
    you need to have the print method outside of the loop

    and wow, i actually helped someone who is more noob than me
    You know you are being brash when I am the one to say this: try and be more respectful. And be sure to correctly address the original poster.

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