Can you help me with writing a small program in Java or C++?

Muhammad Faisal Wahab Khan October 18, 2012
Pinterest Stumbleupon Whatsapp

OK, I know it’s not a place for programmers to hag out, but still I thought let’s just try…

I am trying to write a simple program in java, which shows output just like this:
0………30
0……..34
0…….33
.
.
.
.
.
upto 0

Now the limit is any number. I supposed 30 here. It’s easy with nested loops, but how can I do this with a single for loop? Please you can give answer in any language C++ or java.

Ads by Google

  1. josemon maliakal
    October 18, 2012 at 12:01 pm

    HI the following code will help you
    n=31;
    for(i=0;i<n;i++)
    {
    if(n==0){
    i=n+1;
    }
    else if(i==n){
    cout<<i<<'\n';
    n--;
    i=-1;
    }
    else{
    cout<<i<<" ";
    }
    }

    • salim benhouhou
      October 18, 2012 at 12:11 pm

      i guess this will work

      • josemon maliakal
        October 18, 2012 at 12:18 pm

        thanks salim

        • Muhammad Faisal Wahab Khan
          October 20, 2012 at 1:17 pm

          it didn't work but you were close and made me write the correct code :) thanks

    • Saurabh Banwaskar
      October 19, 2012 at 8:47 am

      ya this will useful !!!!

  2. josemon maliakal
    October 18, 2012 at 12:01 pm

    n=31
    for(i=0;i<n;i++)
    {
    if(n==0){
    i=n+1;
    }
    else if(i==n){
    cout<<i<<'\n';
    n--;
    i=-1;
    }
    else{
    cout<<i<<" ";
    }
    }

    it will do

  3. Burhan Ahmed
    October 18, 2012 at 10:04 am

    from what i understand you want to use "for" loop
    ..

    But i dont understand what output you want from it...

    it would be something like.

    for(int i; i< input.length; i++)
    printf ("%i",i);

Ads by Google