Code សម្រាប់បង្កើតម៉ាទ្រីសអង្កត់ទ្រូងជារៀងត្រីកោណ

image

#include<iostream.h>
#include<conio.h>
void input(int n);
void output(int a[20][20], int n);

void main()
{
    int n;
    cout<<"Enter N:"; cin>>n;
    input(n);
    getch();
}
     void input(int n)
    {
        int i, j, a[20][20];
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            {
                cout<<"Enter a["<<i<<"]["<<j<<"]= ";
                cin>>a[i][j];
            }
        }
        output(a,n);
    }

     void output(int a[20][20], int n)
    { int i, j, m;
      cout<<endl;
      for(i=0; i<n; i++)
      {
         for(j=0; j<n; j++)
         {
             cout<<a[i][j]<<"\t";
         }
            cout<<endl;
      }

      cout<<endl;

      for(j=n-1; j>=0; j–)
      {
         for(i=0; i<n-j; i++)
            cout<<a[i][j+i]<<"\t";
            cout<<endl;
      }
      for(i=1; i<n; i++)
      {
         for(j=0; j<n-i; j++)
         cout<<a[i+j][j]<<"\t";
         cout<<endl;
      }
    }

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s