Thursday 29 March 2012

Mencari Segitiga Dengan Menggunakan C++

#include <conio.h>
#include <iostream.h>

void main()
{
   int a[11][11];
    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)

   {
       if(i==j)
          a[i][j]<<'*';

      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if(i==j)
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }
    cout<<endl;
    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)
   {
       if(i+j==11-1)
          a[i][j]<<'*';
      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if(i+j==11-1)
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }
    cout<<endl;
    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)
   {
       if((i==j)||(i+j==11-1))
          a[i][j]<<'*';
      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if((i==j)||(i+j==11-1))
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }
    cout<<endl;

    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)
   {
       if(i<=j)
          a[i][j]<<'*';
      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if(i<=j)
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }
    cout<<endl;
    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)
   {
       if(i+j<=11-1)
          a[i][j]<<'*';
      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if(i+j<=11-1)
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }
    cout<<endl;
    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)
   {
       if(i+j>=11-1)
          a[i][j]<<'*';
      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if(i+j>=11-1)
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }
    cout<<endl;
    for(int i=0; i<=10; i++)
   for(int j=0; j<=10; j++)
   {
       if(i>=j)
          a[i][j]<<'*';
      else
          a[i][j]<<' ';
   }
   for(int i=0; i<=10; i++)
   {
         for(int j=0; j<=10; j++)
      {
      if(i>=j)
          cout<<'*';
      else
      cout<<' ';
      }
      cout<<endl;
   }

getch();
}

No comments:

Post a Comment