for Robot Artificial Inteligence

14. Application of Matrix Menu

|

Menu

  1. Create
  2. Get
  3. Set
  4. Display

Diagonal

int main()
{
  int * A, n, ch, x;
  printf("Enter Dimension");
  scanf("%d", &n);
  A = int new[n];
  int i,j;
  do
  {
    //Display Menu
    switch(ch)
    {
      case 1:
        for(i=1;i<=n,i++)
        {
          scanf("%d\n", &A[i-1] );
        }
      case 2:
        printf("enter index");
        scanf("%d,%d \n",&i,&j);
        if(i==j)
          printf("%d \n",A[i-1] );
        else
        {
          printf("0");
        }
      case 3:
        printf("Endter row,col, and ele);
        scanf("%d,%d,%d \n",&i,&j,&x);
        if(i==j)
          A[i-1]=x;
        break;
      case 4:
        for(i=1; i<=n; i++)
        {
          for(j=1; j<=n; j++)
          {
            if(i==j)
              printf("%d\n", A[i-1] );
            else
              printf("0");
          }
        }
    }
  }

}

Lower Triangular

int main()
{
  int * A, n, ch, x;
  printf("Enter Dimension");
  scanf("%d", &n);
  A = int new[n];
  int i,j;
  do
  {
    //Display Menu
    switch(ch)
    {
      case 1:
        for(i=1;i<=n,i++)
        {
          scanf("%d\n", &A[i-1] );
        }
      case 2:
        printf("enter index");
        scanf("%d,%d \n",&i,&j);
        if(i==j)
          printf("%d \n",A[i-1] );
        else
        {
          printf("0");
        }
      case 3:
        printf("Endter row,col, and ele);
        scanf("%d,%d,%d \n",&i,&j,&x);
        if(i>=j)
          A[i+(i-1)/2+j-1]=x;
        break;
      case 4:
        for(i=1; i<=n; i++)
        {
          for(j=1; j<=n; j++)
          {
            if(i>=j)
              printf("%d\n", A[i+(i-1)/2+j-1] );
            else
              printf("0");
          }
        }
    }
  }

}

Quiz

Comments