مثلث متساوی الساقین با ارتفاع n را با استفاده از علامت ستاره ها   به زبان سی پلاس پلاس چاپ شود

 

#include
using namespace std;
void printStars(int stars);
void printSpaces(int spcs);
int main()
{
    int n;
    cout<<"Enter number of rows: ";
    cin>>n;
    for (int i = 1 ; i <= n ; i ++)  //row main loop
    {
            printSpaces(n-i);
            printStars(i*2-1);
            cout<    }
    fflush(stdin) ; getchar();  return 0;       }
 
 
void printStars(int stars)
{
   int j;
   for (j=1; j<=stars; j++) 
       cout << "*"; 
}
 
void printSpaces(int spcs)
{
    int j;
    for (j=1; j<=spcs; j++)
        cout <<" ";
}


موضوعات مرتبط: C++ ، C

| | محمد صفائیان |