while loop or doo loop
the output should be like this

1
12
123
1234
123
12
1

and

1234
123
12
1
12
123
1234

tnx

Recommended Answers

All 10 Replies

#include <iostream>

int main()
{
  while(1)
  {
    std::cout << "1" << std::endl << "12" << std::endl << "123" << std::endl << "1234" << std::endl << "123" << std::endl << "12" << std::endl << "1" << std::endl;
    break;
  }
}

im sory but thats not the kind of programming that my prof wants

it like dis for(x=1;x<=1;++) but i dont know how XD

That's a for loop. You asked for a while loop. Which do you want?

while loops or do loop aswell sir how ever i thinks its like this (x=1;x<=1;++)

Show your code we will help with the rest.

Codul este entru prima varianta. Pentru a 2 faci mici modificari max initial 4, inc false, if(max == 1) inc = true; , si while(max != 5)

#include<stdio.h>

int main(){
    int i,max = 1;
    bool inc = true;

    while(max != 0){
        i = 1;
        while(i <= max){
            printf("%d",i);
            i++;
        }
        printf("\n");

        if(max == 4) // Pana la cat doresti sa mearga
            inc = false;
        if(inc)
            max++;
        else
            max--;
    }
    return 0;
}

Nicolae_1: First off, this is an English language forum, and giving an answer in another language (especially one poorly known outside of its home country such as Romanian) is extremely rude and unlikely to be helpful. Even if the OP were a native speaker - which is not the case in this instance - it is a problem for anyone else who isn't and is trying to read the response. Please write in English as best you can; we are patient with non-English speakers, up to a point at least, so long as you use actual full English words and sentences rather than text-speak.

Second, in the future, pelase do not simply hand over completed code to the querents; it amounts to helping them cheat, and is unhelpful to either them or yourself. The forum is here to give advice and assistance, not solve homework problems for free. I know you meant well, and you aren't the first to make this mistake (I did a number of times myself, when I got frustrated with the process of helping), but it really isn't a good policy to answer other posters' questions so directly.

Member Avatar for iamthwee

Hi tan, here is your solution using a for loop.

#include <iostream>
#include <string>

using namespace std;

int main()
{
  for(x=1;x<=1;++) 
  {

  }
  cout << "1" <<endl;
  cout << "12" <<endl;
  cout << "123" <<endl;
  cout << "1234" <<endl;
  cout << "123" <<endl;
  cout << "12" << endl;
  cout << "1" <<endl;

  return 0;
}

im sory but thats not the kind of programming that my prof wants

So your saying your in a class; yet you have no idea how to start the assignment? The either means your prof didn't prepair you or you didn't listen (which is why you're getting silly responces here).

If you are able to get some of it done, we can point you in the right direction. If you don't know basic C++ as all, we can direct you to a tutorial.

#include<iostream>

using namespace std;

int main()
{
int i=1,a,j=1;
cout<<"\n Enter the number until which looping is to be done";
cin>>a;
for(i=1;i<=a;i++)
{
    cout<<"\n";
    j=1;
    do {
    cout<<j;
    j++;
    }while(j<=i);
    if(i==a)
    {
    for(int k=a-1;k>0;k--)
    {
    cout<<"\n";
    j=1;
        do {
            cout<<j;
        j++;
        }while(j<=k);
    }
    }
}
for(int p=a;p>0;p--)
{
    cout<<"\n";
    j=1;
    do {
    cout<<j;
    j++;
    }while(j<=p);
    if(p==1)
    {
    for(int l=2;l<=a;l++)
    {
    cout<<"\n";
    j=1;
        do {
            cout<<j;
        j++;
        } while(j<=l);
    }
    }
}

cin.get();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.