Computer Science, asked by Nancy2468, 1 year ago

write a program in C++ to display the following pattern. 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Answers

Answered by AskewTronics
0

Bellow are the code in c++ language for the above question:

Explanation:

#include <iostream> //header file.

using namespace std;

int main() //main function definition.

{

   float size,i,j; //variable declaration.

   cout<<"Enter the size of the series"; //print the message to the user.

   cin>>size;//take the input from the user.

  for(i=1;i<=size;i++)//first for loop.

  {

    for(j=1;j<=i;j++)//second for loop.

     cout<<j<<" ";// print the series.

    cout<<"\n"; //to change the line.

  }

   

   return 0; //return statement.

}

Output:

  • If the user inputs 1 then it will prints only 1.
  • If the user inputs 5 then it will prints the above series.

Code Explanation :

  • The above code is in c++ language, in which the size is needed to enter by the user.
  • Then there are two for loop in which, first is used to decide the size of the series and the second is used to decide the length of the series.

Learn More:

  • Programs : https://brainly.in/question/9996665
Similar questions