Posts

Showing posts from January, 2020

print letter T using for loop in c++ language

Image
Write a program that reads in a number and prints out the letter T using '*' characters with each line in the T having width n.  Further, the length of the horizontal bar should be 3n, and that of the vertical bar 2n.   #include<iostream> using namespace std; int main() {  //Double slash is used to give comment in c++ language.    long i,j,k,n,x,z;   cout<<"enter the value of n: ";   cin>>n;   for(i=0;i<n;i++)          //this loop is used to print n number of  rows   {      for(j=0;j<3*n;j++)    //this loop is used to print 3*n number of columns     {cout<<"*";}    cout<<endl;                //endl moves the cursor to next line.   }   for(k=0;k<2*n;k++)    //this loop is used to print 2* n number of  rows   {   ...

printing triangle pattern using for loops in c++

Image
                                  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 .              ...