Tuesday, August 14, 2012

Reverse Diagonal elements of a Square Matrix using single for loop in C language

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,a[20][20],k=1,n;
printf("\n Enter the size of square matrix");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=k;
k++;
}
}
printf("\n Reverse Diagonal elements:");
for(i=0,j=0;i<n,j<n;i++,j++)
{
printf("\n %d",a[i][n-1-i]);
}
getch();
}

No comments:

Post a Comment

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...