-->

WAP to print upper triangular matrix of order mxn.

using codeblocks
-----------------------------------
//WAP to print upper triangular matrix  of order mxn.
#include<stdio.h>
int main()
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                               // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("upper triangular matrix is\n");  // message for upper triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i<=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of upper triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 return 0;       
}
-------------------------------------------------------------------
using turboC++
--------------------------------------------------------------
//WAP to print upper triangular matrix  of order mxn.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                               // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("upper triangular matrix is\n");  // message for upper triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i<=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of upper triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 getch();       
}


//WAP to get sum of diagonal elements of an array of order 'mxn'.

//WAP to get sum of diagonal elements of an array of order 'mxn'.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("for sum, the matrix must be square\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("the matrix is\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("------------------\n");             // for transposed matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           if(i==j)                          // testing whether the locations are same or not
           {
           sum=sum+matrics_1[i][j];
            }                                // display of matrix with trasnposed elemnts
       }
       printf("\n");
}

printf("sum=%d",sum);
     
getch();
}

------------------------------------------------------------------------------------------
using codeblocks.
-------------------------------------------------------------------------------------
//WAP to get sum of diagonal elements of an array of order 'mxn'.
#include<stdio.h>
int main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("for sum, the matrix must be square\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("the matrix is\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("------------------\n");             // for transposed matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           if(i==j)                          // testing whether the locations are same or not
           {
           sum=sum+matrics_1[i][j];
            }                                // display of matrix with trasnposed elemnts
       }
       printf("\n");
}

printf("sum=%d",sum);
 return 0;       
}

WAP to transpose a matrix/array of order mxn.

//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("before transpose\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<total_col;i++)
{
  for(j=0;j<total_row;j++)
       {
        printf("%d",matrics_1[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}     
getch();
}
------------------------------------------------------------------------------------------
using codeblocks/devc++  with return concept
---------------------------------------------------------------------------------------
//WAP to transpose  a matrix/array of order mxn.
#include<stdio.h>
int main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("before transpose\n");             // message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)             
       {
           printf("%d",matrics_1[i][j]); // display of matrix
        }
        printf("\n");                    // display in next row
}
printf("after transpose\n");             // for transposed matrix
for(i=0;i<total_col;i++)
{
  for(j=0;j<total_row;j++)
       {
        printf("%d",matrics_1[j][i]);    // display of matrix with trasnposed elemnts
       }
       printf("\n");
}


 return 0;       
}

-------------
change the rows to column and vice versa.

WAP to get sum of elements of first row of a matrix of order 'mxn'.

//WAP to get sum of elements of first row of a matrix of order 'mxn'.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("'%d",&total_row);
printf("'enter total columns(n)\n");;
scanf("%d",&total__col);
printf("enter elements of matrix\n");
for(i=0;i<=0;i++)                            // for rows
{
  for(j=0;j<total_col;j++)                // for columns
       {
           scanf("%d",&matrics_1[i][j]);
           sum=sum+matrics_1[i][j];
        }
}


           printf("sum=%d",sum);
     
getch();
}



WAP to get sub-matrix of a matrix of order 'mxn'.

//WAP to get sub-matrix of a matrix of order 'mxn'.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
int sub_row,sub_col;
printf("enter total number of rows(m)\n");
scanf("'%d",&total_row);
printf("'enter total columns(n)\n");;
scanf("%d",&total__col);
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           scanf("%d",&matrics_1[i][j]);
         
        }
}
printf("now enter total rows and columns to be \n");
printf("enter total number of rows(m)\n");
scanf("'%d",&sub_row);
printf("'enter total columns(n)\n");;
scanf("%d",&sub__col);
for(i=0;i<sub_row;i++)
{
  for(j=0;j<sub_col;j++)
       {
           printf("%d",matrics_1[i][j]);
         
        }

     printf("\n");
}     
getch();
}



WAP to get sum of elements of an array of order 'mxn'.

//WAP to get sum of elements of an array of order 'mxn'.
#include<stdio.h>
#include<conio.h>
void main()
{
int matrics_1[100][100];
int i,j,sum=0;
int total_row,total_col;
printf("enter total number of rows(m)\n");
scanf("'%d",&total_row);
printf("'enter total columns(n)\n");;
scanf("%d",&total__col);
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           scanf("%d",&matrics_1[i][j]);
           sum=sum+matrics_1[i][j];
        }
}


           printf("sum=%d",sum);
       
getch();
}


WAP to initialize elements of an array of size 2x2. Then display that.

//WAP to initialize elements of an array of size 2x2. Then display that.
#include <stdio.h>
#include<conio.h>

void main()
{
    int a[2][2]={1,2,3,4};
    int i,j;
    for(i=0;i<=1;i++)
    {
        for(j=0;j<=1;j++)
        {
            printf("%d",a[i][j]);
        }
    
     printf("\n");
  }
    getch();
}


-----------------------------------------------------------------------------------
or
----------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include<conio.h>
void main()
{
    int a[2][2]={{1,2},{3,4}};
    int i,j;
    for(i=0;i<=1;i++)
    {
        for(j=0;j<=1;j++)
        {
            printf("%d",a[i][j]);
        }
    
    printf("\n");
}
    getch();
}