Sunday, March 29, 2009

C Programs with Solution Logic

  • Transpose of a Matrix
Interchanging the Rows with Columns or Vice-Verse
for(i=0;i&k;i++)
for(j=i+1;j&l;j++)
{
temp=mat[i][j];
mat[i][j]=mat[j][i];
mat[j][i]=temp;
}
  • Finding the Saddle point of a Matrix
A matrix a is said to have a saddle point if some entry a[I][j] is the smallest value in the ith row and the largest value in the jth column. A matrix may have more than one saddle point.

for Eg:
7 6 5
1 8 1
2 9 2

Here saddle Point value is 5.

  • How to find year is leap year.
if a year is divisible by 4 and not by 100 is called leap year.
if a year is divisible by 400 is called leap year.

  • How to swap two variables without using temporary variable?
a^=b^=a^=b

How to know system is using little Endian or Big Endain?
int i=1;
if( * (char *)&i == 1)
printf("Little Endian");
else
printf("Big Endian");

1 comment: