Thread: For Loop Issue

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    11

    For Loop Issue

    I've typed up this code below, but need to find Z. Do I need printf to show what z is and if so, how would I implement it?

    insert
    Code:
    int n, z;
    
    z=1000
    for (n=0; n<100; n+=100)
    {
      z++;
    }
    Can anyone help me?

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    printf("%d\n",z);

    edit:

    %d : means print an 'int' value
    \n : add a carriage return/line feed

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Dynesclan View Post
    [...]but need to find Z.

    insert
    Code:
    int n, z;
    
    z=1000
    for (n=0; n<100; n+=100)
    {
      z++;
    }
    Can anyone help me?
    Here they are!
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by msh View Post
    Here they are!
    You've read the "Find x" funny haven't you?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by Dynesclan View Post
    I've typed up this code below, but need to find Z. Do I need printf to show what z is and if so, how would I implement it?

    insert
    Code:
    int n, z;
    
    z=1000
    for (n=0; n<100; n+=100)
    {
      z++;
    }
    Can anyone help me?
    Hey there - I don't think that this will work the way you expect.

    In the for statement you have
    Code:
    n+=100
    This is the same as
    Code:
    n=n+100
    and because n starts at 0 and can't be equal or over 100, it will only execute once and z will be 1001.

  6. #6
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by iMalc View Post
    You've read the "Find x" funny haven't you?
    I'm easily amused.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. for loop issue
    By begginer in forum C Programming
    Replies: 8
    Last Post: 03-20-2011, 08:22 AM
  2. Loop issue in tax program
    By mistymoon1966 in forum C Programming
    Replies: 4
    Last Post: 10-31-2009, 02:04 PM
  3. Loop issue
    By Gordon in forum Windows Programming
    Replies: 14
    Last Post: 01-07-2008, 02:04 AM
  4. While loop issue
    By exvor in forum C Programming
    Replies: 2
    Last Post: 09-17-2005, 11:13 AM