DEV Community

Davron
Davron

Posted on

C++ Loopga doir masalalar. Chap Pascal Uchburchagi.

Raqamlardan foydalanib Chap Pascal Uchburchagini chop etish.

Natija (inputga 7 kiritildi deb tasavvur qilinsin):

            1 
          1 2 
        1 2 3 
      1 2 3 4 
    1 2 3 4 5 
  1 2 3 4 5 6 
1 2 3 4 5 6 7 
  1 2 3 4 5 6 
    1 2 3 4 5 
      1 2 3 4 
        1 2 3 
          1 2 
            1       
Enter fullscreen mode Exit fullscreen mode

Kod:


    cout << "Chap Paskal Uchburchagi qatorlari sonini kiriting = ";
    cin >> qatorlar;

    cout << "Chap Paskal Uchburchak shakli\n"; 

    for(i = 1; i <= qatorlar; i++)
    {
        for(j = i; j < qatorlar; j++)
            {
          cout << "  ";
        }
        for(k = 1; k <= i; k++)
          {
            cout << k << " ";
          }
        cout << "\n";
    }   

    for(i = qatorlar; i >= 1; i--)
    {
        for(j = i; j <= qatorlar; j++)
        {
            cout << "  ";
        }
        for(k = 1; k < i; k++)
        {
            cout << k << " ";
        }
        cout << "\n";
    }

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Savol va Takliflar uchun Telegram ❤️.

Discussion (0)