for(int i=5;i>=1;i--)
    {
    for(int j=5-i;j>=1;j--)
    {
    cout<<" ";
    }
    for(int k=1;k<=i;k++)
    {
    cout<<"* ";
    }
    cout<<endl;
    }

sorry but can someone explain this coding to me? T.T''

Recommended Answers

All 2 Replies

Maybe this will help :

#include<iostream>
using namespace std;

int main()
{

	for(int i=5;i>=1;i--) 
	{
		for(int j=5-i;j>=1;j--)  
		{
			cout<<"-";
		}
    
		for(int k=1;k<=i;k++)  
		{
			cout<<"* ";
		}
		
		cout<<endl;

    }


	return 0;

}

Look at the output, and trace the loop from i = 5 till i = 1.

okay..got it..thx!!
But, if i wan to design for another pattern.
What is the key to make that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.