facebook like button

27 April, 2011

program 35: printing the positions of a matrix

The need:
     This program takes takes dimensions of a matrix as input and prints all the positions of that matrix. Here position means the row and column of an element.
The code: 
--------------------------------------------
#include<stdio.h>
main()
{
    int j,i,m,n;
    printf("Enter the number of rows..\n");
    scanf("%d",&m);
    printf("Enter the number of columns..\n");
    scanf("%d",&n);
    for (i=0;i<m;i++)
    {
        for (j=0;j<n;j++)
        {
            printf ("%d%d ",i+1,j+1);
        }
    printf("\n");
    }
} 
--------------------------------------------
The approach: 
This program illustrates how we can print in 2 dimensional space(like matrix here). Run the program. This program asks you to enter the number of rows and columns of the matrix and then prints index of each element of that matrix. I did not make this program at that time but I have put its here intentionally because in next post I am going to tell you how to store a matrix in a C program. I am going to introduce the concept of 2 dimensional arrays which can store a matrix.

No comments:

Post a Comment

feel free to ask your doubts... if any
you can post your doubts on
www.facebook.com/programsimply