Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Problem Statement - Triangular Number series using the Flyod’s triangle method
Write a program to print a series of triangular numbers starting 1 using the property of a flyod’s triangle where the right most number is a triangular number. Accept the number of terms to be printed from the user. The series output would be 1 3 6 10 15 ……
Related codes are those codes where similar programming concepts are in use. They are different from alternate codes in the sense that they may not have same purpose and results.
:
Run Output
Print how many terms of triangular number(s)? 10
1 3 6 10 15 21 28 36 45 55
int terms; //The terms count will be collected by the the user
int k=1; //This is the beginning number from where the triangular numbers will start
cout<<“Print how many terms of triangular number(s)? “; cin>>terms;
Here we are collecting the the number of terms to be printed
for(int i=1;i<=terms;i++) //This outer loop is for terms increment { for(int j=1;j<=i;j++) //This inner loop is for incrementing for each column rule as per flyod’s triangle { if(j==i) cout<<k<<” “; //The printed count begins here when the last number of triangle is to be printed. k++; //In each iteration it is incremented whether it is row or column } }