-->





Translate

inverted triangle shape in c++ code using for loop

2 comments
write a c++ program which displays an inverted triangle using nested for loop and asterisk character

Use any Compiler IDE you want.
Required Output should be look like below image.
inverted triangle shape in c++ code using for loop and asterisk character

 

Compiler used: CodeBlocks c++ Compiler
c++ code:



#include<iostream>
using namespace std;
int main()
{

     cout<<"\"Inverted Triangle Shape\"\n\n";


  int w=6;

   for(int g=0;g<9;g++)
 {
  cout<<"*";    // Displaying asterisk here
 }
  cout<<endl; // endl is for new line

  for(int a=1;a<=3;a++)
 {

    for(int b=0;b<a;b++)
   {
    cout<<" ";    // displaying space here
   }
    cout<<"*";


      for(int c=1;c<w;c++)
     {
      cout<<" ";
     }
      cout<<"*"<<endl;
      w=w-2;
 }

  for(int e=1;e<=1;e++)
 {

    for(int f=4;f>=e;f--)
   {
    cout<<" ";
   }
    cout<<"*";
 }

  return 0;
}


sample output

inverted triangle shape code using for loop sample output c++ programming



These kinds of programs are basic level program can be coded in more than one way it is recommended to change the logic of program and do experiment with the code for better understanding

More C++ Shapes Here

2 comments:

  1. what should i do when i have to make it user based....like user have to give a number then the output will show accordingly to the given number

    ReplyDelete
  2. Can u plz upload the same type of ques in c coding like using printf and all instead of cout

    ReplyDelete