Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

How to do this While Statement..

  • 28-10-2009 12:47pm
    #1
    Closed Accounts Posts: 314 ✭✭


    Write a program using a while loop to print out the numbers 1 - 10 in descending order on the same line and each number is separated by a comma (e.g. 1,2,3,4,5,6,7,8,9,10)..

    How do u do this please?




    main()

    {

    int num ;


    while ( )
    {
    printf(" " ) ;
    }

    printf(" " ) ;
    }


Comments

  • Closed Accounts Posts: 190 ✭✭jasonbourme.cs


    x=10
    do While X > 0
    x=x-1
    loop

    something like this ?


  • Closed Accounts Posts: 314 ✭✭Joebits


    Ok how do i get it in descending Order??

    This code works

    main(){

    int i = 1;

    while ( i < 11 )

    {
    printf(" %d,", i);
    i = i + 1;
    }
    getch() ;
    }


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Joebits wrote: »
    Ok how do i get it in descending Order??

    This code works

    main(){

    int i = 1;

    while ( i < 11 )

    {
    printf(" %d,", i);
    i = i + 1;
    }
    getch() ;
    }

    Start with i=10, while (i>0) and i = i - 1

    Alternatively (to ensure there's no trailing comma)

    $arr=array();
    for ($x=0;$x>0;$x--) $arr[]=$x;
    echo implode(",",$arr);


Advertisement