Monday, September 10, 2018

Floyd's Triangle

// Program to print Pattern - Triangle with numbers
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int num,print_val,r,c; // To input number of lines
cout<<"Enter Number "; cin>>num;
for(r=1,print_val=1; r<=num; r++) {
for(c=1 ; c<=r; c++,print_val++)
{
cout<<print_val<<" "; // will print col num
//in a single line
}
cout<<"\n"; // At end of inner loop next
//line will come in a new line
}
getch();
}

No comments:

Post a Comment