Showing posts with label Write a Programs to print triangles using numbers and characters. Show all posts
Showing posts with label Write a Programs to print triangles using numbers and characters. Show all posts

Sunday, 15 October 2017

Write a Programs to print triangles using numbers and characters

Write a Programs to print triangles using numbers and characters

In this program we learn you how to make a triangle using the number and star;\


You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop



Example 1: write a Program to print triangle using *
*
* *
* * *
* * * *
* * * * *

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i, j, rows;

    cout<<" Please Enter the rows: ";
    cin>>rows;

    for(i=1; i<=rows; ++i)
    {
        for(j=1; j<=i; ++j)
        {
            cout<<"* ";
        }
           cout<<"\n";
        }
      return 0;
      }
Output
------------------
Plaese enter the rows
6
*
* *
* * *
* * * *
* * * * * *

Example 1: write a Program to print triangle using number

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i, j, rows;

    cout<<"Please Enter the rows: ";
    cin>>rows;

    for(i=1; i<=rows; ++i)
    {
        for(j=1; j<=i; ++j)
        {
            cout<<j;
        }
           cout<<"\n";
        }
      return 0;
      }
output
-----------------
Please enter the row
8

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

---------------------------------------------------------------------------------------------------
 The people who want to learn programming language.this website very beneficial for those people.