Wednesday, February 13, 2013

Program To Rotate the Matrix

/*
Program to Rotate the Given Matrix:

*/
#include<stdio.h>
void main()
{
    int a[2][3]={0,1,0,1,1,1};
    int i,j;
    int i1,j1;
    printf("Matrix A:\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<3;j++)
            printf("%d\t",a[i][j]);
        printf("\n");
    }
    printf("Matrix After Rotation:\n");
    for(i=2;i>=0;i--)
    {
        for(j=0;j<2;j++)
            printf("%d\t",a[j][i]);
        printf("\n");
    }
}

/*
Suppose the Given Matrix be:

0    1    0   
1    1    1

Then the result should be:

0    1   
1    1   
0    1

//Simple Logic Take Care of loop
*/

No comments:

Post a Comment