Followers

Saturday, April 15, 2023

Program To Print A Triangle Pattern

 Program:

 #include <iostream>    
 using namespace std;    
 int main() {    
  cout<<"Program To Print A Triangle"<<endl;  
  cout<<"*"<<endl;  
  cout<<"**"<<endl;  
  cout<<"***"<<endl;  
  cout<<"****"<<endl;  
  cout<<"*****"<<endl;  
  cout<<"******"<<endl;    
  return 0;    
 }  
Output:












Working Of The Program:
1. This is a C++ program written to print a triangle using asterisks (*) on the console.
2. The first line of the code includes the iostream header file, which is needed for input/output operations.
3. The 'using namespace std' statement is used to avoid writing the 'std::' prefix before every standard library function call.
4. The main() function is the entry point of the program, which contains the code to be executed.
5. The first cout statement prints a string on the console, which indicates the purpose of the program.
6. The next six cout statements print the triangle using asterisks in a pattern of increasing the number of asterisks in each row.
7. Finally, the 'return 0;' statement is used to exit the program with a status of 0, indicating successful execution.

No comments:

Post a Comment

Program to Find the Length of a String

Program: #include <iostream> using namespace std; int main() { string a; cout<<"Enter the string...