C ode to print triangle in c++ #include<iostream> using namespace std; int main() { //Double slash is used to give comment in c++ language. int i,j,k; for(i=0;i<7;i=i+1) { for(k=20-i;k>=0;k--) //loop for spacing {cout<<" ";} for(j=0;j<=i;j++) {cout<<"* ";} //don't forget to give one space after * cout<<endl; //endl move the cursor to next line } return(0); } OUTPUT: NOTE: In the above code i used k=20-i, you can use any number in place of 20 but the number should be more than the total number of asterisk(*) present in the last line of triangle pattern . ...
Comments
Post a Comment