C Program to Print Corner Elements of Matrix

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for corner elements of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
      system("cls");
      int a[50][50],m,n,r,c;
    xyz:printf("Enter values of row and column");
      scanf("%d %d",&m,&n);
      if(m>50 || n>50)
      {
          printf("Invalid values of row and column");
          goto xyz;
      }
      else
      {
            printf("\n Enter elements in matrix");
            for(r=0;r<m;r++)
            {
                for(c=0;c<n;c++)
                {
                    scanf("%d",&a[r][c]);
                }
            }
          
          printf("\n Elements in matrix\n");
            for(r=0;r<m;r++)
            {
                for(c=0;c<n;c++)
                {
                    printf("%4d",a[r][c]);
                }
                printf("\n");
            } 
            printf("\n Corner elements of matrix");
             for(r=0;r<m;r++)
            {
                for(c=0;c<n;c++)
                {
                    if(r==0 && c==0)
                      printf("\n Top left element is: %d",a[r][c]);
                    if(r==0 && c==n-1)
                      printf("\n Top right element is: %d",a[r][c]);
                     if(r==m-1 && c==0)
                      printf("\n Bottom left element is: %d",a[r][c]);
                    if(r==m-1 && c==n-1)
                      printf("\n Bottom right element is: %d",a[r][c]);
                }
            } 
      }

    return 0;
}

 

 

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *