C++ PROGRAM TO PRINT ALPHABET TRIANGLE!!!
|ALPHABET TRIANGLE|
There are different triangles that can be printed. Triangles can be generated by alphabets or numbers.
In this C++ program, we are going to print alphabet triangles.
- Let’s start the program with the header file
““#include<iostream>” →Input-output continuous bytes of data.
“using namespace std;” →used to store variable name.
“int main()” →returns datatype function.”
“{ char ch=’A’;
int i, j, k, m;
for(i=1;i<=5;i++)”
- In char we have given (ch=A). And we have declared four variables (i,j,k,m) are defined in integer.
char →data type used for the storage of letter
int → data type used to store integer (numbers)
“ { for(j=5;j>=i;j- -)
cout<<” “;
for(k=1;k<=i;k++)
cout<<ch++;
ch- -;
for(m=1;m<i;m++)
cout<- -ch;
cout<<”\n”;
ch=’A’;
}
return 0; }”
FOR LOOP:
When you know exactly how many times you want to loop through a block of code, use the
for
loop instead of awhile
loop:
Syntax
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
Statement 1 is executed (one time) before the execution of the code block.
Statement 2 defines the condition for executing the code block.
Statement 3 is executed (every time) after the code block has been executed.
return 0 →which means the program is executed successfully.
SOURCE CODE:
OUTPUT:
REFERENCE LINK:
To know more about C++ PROGRAM, Login “GUVI”