-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Tuesday 14 July 2015

Making a right-angled triangle in C++

Hello and Asalam o Alikum.I hope you all are fine by the grace of Allah Almighty.
Today I am here with a very famous program of nested loops.

You have often made a right-angled triangle on your notebook or register but today I will show you how to make it in C++. Its coding is very simple and interesting

So,have a look at its source code.

Source code


Output


How the program works? 

The outer loop of this program is from 0-5. It starts its iteration when the value is 1.
Then it jumps to the inner loop whose loop is from 1 to outer loop.As the value of loop is one, so 1 star will be displayed.

Again it jumps to the outer loop where the value now becomes 2.Then it jumps to the inner loop and the same process is repeated.This time two stars are displayed on the next line.

This process is repeated again and again until the value of outer loop becomes 6 which is against the given condition. So ,the loop is terminated.

No comments:

Post a Comment