In this article I would like to share with you a sample program that I wrote using C++ as my programming language that will display an inverted triangle pattern image. For this code I'm using two for loop statement to achieve the pattern design of the inverted triangle.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.
Program Listing
#include <iostream>
#include <stdlib.h>
using namespace std;
int a=0, b=0, c=0;
void display()
{
cout << "\t INVERTED TRIANGLE";
cout << "\n\n";
for(a=20;a>=1;a-=1)
{
for(b=20;b>a;b-=1)
{
cout << " ";
}
for(c=1;c<(a*2);c+=1)
{
cout << "^";
}
cout << "\n";
}
cout << "\n\n";
}
int main()
{
display();
system("pause");
}
#include <stdlib.h>
using namespace std;
int a=0, b=0, c=0;
void display()
{
cout << "\t INVERTED TRIANGLE";
cout << "\n\n";
for(a=20;a>=1;a-=1)
{
for(b=20;b>a;b-=1)
{
cout << " ";
}
for(c=1;c<(a*2);c+=1)
{
cout << "^";
}
cout << "\n";
}
cout << "\n\n";
}
int main()
{
display();
system("pause");
}
No comments:
Post a Comment