Help me coding

This is a discussion on Help me coding within the C Programming forums, part of the General Programming Boards category; #include<stdio.h> int main() { int i=1; while(i<=9) { printf("The value of i is :%d",i); ...................... } printf("wrong input"); } anyone ...

  1. #1
    Registered User hakimstm1b's Avatar
    Join Date
    Sep 2010
    Posts
    30

    Help me coding

    #include<stdio.h>
    int main()

    {
    int i=1;

    while(i<=9)
    {

    printf("The value of i is :%d",i);

    ......................
    }

    printf("wrong input");

    }

    anyone can tell right formula that has put in blank , so it can show output 2,4,6,8

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Use code tags when posting code.

    To see if a number is even, you can use the modulus operator:
    Code:
    if (i % 2 == 0)
    {
        /* i is even. */
    }

  3. #3
    Registered User hakimstm1b's Avatar
    Join Date
    Sep 2010
    Posts
    30
    no... i dont want use if .....i want use that "While", i just want to no the formula that i can use?

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Put the if expression inside the while loop and only print i when the expression is true. Or you could simply start at i=2 and increment it with two instead of one each iteration.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    Bored with asking OP to use code tags - time for plan B
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 07:09 AM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 01:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM

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