News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Question about Loops

Started by Apbullington18, October 23, 2018, 05:47:38 PM

Previous topic - Next topic

Apbullington18

#include <stdio.h>
main()
{
int x = 0;
while (x < 5)
{
    printf(" ",x,"\n");
    x++;
}
return 0;
}

I can't get this program to run in CodeBlocks.  It's just a simple while loop, but nothing comes out when run.  I'm new to coding so forgive me if i'm naive. 

raynebc

That printf statement isn't doing what you think it is, it's just printing space characters.  You'll probably want to do printf(" %d\n", x); instead.  If you enabled all the optional warnings in your compiler, you would likely get a warning that you passed too many arguments (ie, x and "\n" being ignored because the format string didn't call for the use of any additional arguments).

Apbullington18