C Program to sort the matrix rows and columns.

C Program to sort the matrix rows and columns. This C program accept a order MxN Matrix, and sort all rows of the matrix in ascending order and all columns in descending order . In this program, we use the for statement to read two dimension arrays. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>

void main ()
{
static int ma[10][10],mb[10][10];
int i,j,k,a,m,n;

printf ("Enter the order of the matrix n");
scanf ("%d %d", &m,&n);

printf ("Enter co-efficients of the matrix n");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf ("%d",&ma[i][j]);
mb[i][j] = ma[i][j];
}
}
printf ("The given matrix is n");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",ma[i][j]);
}
printf ("n");
}

printf ("After arranging rows in ascending ordern");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
for (k=(j+1);k<n;++k)
{
if (ma[i][j] > ma[i][k])
{
a = ma[i][j];
ma[i][j] = ma[i][k];
ma[i][k] = a;
}
}
}
} /* End of outer for loop*/

for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",ma[i][j]);
}
printf ("n");
}

printf ("After arranging the columns in descending order n");
for (j=0;j<n;++j)
{
for (i=0;i<m;++i)
{
for (k=i+1;k<m;++k)
{
if (mb[i][j] < mb[k][j])
{
a = mb[i][j];
mb[i][j] = mb[k][j];
mb[k][j] = a;
}
}
}
} /* End of outer for loop*/

for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",mb[i][j]);
}
printf ("n");
}

} /*End of main() */
Read more Similar C Programs
C Basic.

C Matrix.

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C program to find the sparse matrix

C program to accept a matrix and determine whether it is a sparse matrix or not?. A sparse matrix is a matrix, which has more zero elements than nonzero elements. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>

void main ()
{
static int m1[10][10];
int i,j,m,n;
int counter=0;

printf ("Enter the order of the matixn");
scanf ("%d %d",&m,&n);

printf ("Enter the co-efficients of the matixn");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf ("%d",&m1[i][j]);
if (m1[i][j]==0)
{
++counter;
}
}
}
if (counter>((m*n)/2))
{
printf ("The given matrix is sparse matrix n");
}
else
printf ("The given matrix is not a sparse matrix n");

printf ("There are %d number of zeros",counter);

} /* EN dof main() */
Read more Similar C Programs
Matrix Programs
Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C program to accept an integer find the sum of the digits in it

C program to accept an integer find the sum of the digits in it. In this program, we accept an integer and get the digits by using while() and % operator, after that we add that digits to the sum variable. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>

void main()
{
long num, temp, digit, sum = 0;

printf("Enter the numbern");
scanf("%ld", &num);

temp = num;

while(num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
}

printf("Given number =%ldn", temp);
printf("Sum of the digits %ld =%ldn", temp, sum);
} /* End of main()*/
Read more Similar C Programs
C Basic

Airthmatic Operators

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to interchange the main diagonal elements of the matrix

C Program to interchange the main diagonal elements of the matrix. This Program will accept a matrix of order M x N and store its elements and interchange the main diagonal elements of the matrix with that of the secondary diagonal elements .   Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
void main ()
{

static int ma[10][10];
int i,j,m,n,a;

printf ("Enetr the order of the matix n");
scanf ("%d %d",&m,&n);

if (m ==n )
{
printf ("Enter the co-efficients of the matrixn");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf ("%dx%d",&ma[i][j]);
}
}

printf ("The given matrix is n");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",ma[i][j]);
}
printf ("n");
}

for (i=0;i<m;++i)
{
a = ma[i][i];
ma[i][i] = ma[i][m-i-1];
ma[i][m-i-1] = a;
}

printf ("THe matrix after changing the n");
printf ("main diagonal & secondary diagonaln");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",ma[i][j]);
}
printf ("n");
}
}
else
printf ("The givan order is not square matrixn");

} /* end of main() */
Read more Similar C Programs
Matrix Programs
Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C program to find the frequency of odd numbers and even numbers in the input of a matrix

C program to find the frequency of odd numbers and even numbers in the input of a matrix. Program will check the element type, if Matrix element is even, it ads 1 to even counter otherwise ad 1 to odd counter. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

void main ()
{
static int ma[10][10];
int i,j,m,n,even=0,odd=0;

printf ("Enter the order ofthe matrix n");
scanf ("%d %d",&m,&n);

printf ("Enter the coefficients if matrix n");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf ("%d", &ma[i][j]);
if ((ma[i][j]%2) == 0)
{
++even;
}
else
++odd;
}
}
printf ("The given matrix isn");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",ma[i][j]);
}
printf ("n");
}

printf ("nThe frequency of occurance of odd number = %dn",odd);
printf ("The frequency of occurance of even number = %dn",even);

} /* End of main() */
Read more Similar C Programs
Matrix Programs
Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to find second largest and second smallest element in an array

Arrays in C,
C Program to find second largest and second smallest element in the array.  Program will accept a list of data items and find the second largest and second smallest elements in it. And also compute the average of both. And search for the average value whether it is present in the array or not. Display appropriate message on successful search.  Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/


#include <stdio.h>

void main ()
{
 int number[30];
 int i,j,a,n,counter,ave;

 printf ("Enter the value of Nn");
 scanf ("%d", &n);

 printf ("Enter the numbers n");
 for (i=0; i<n; ++i)
  scanf ("%d",&number[i]);

 for (i=0; i<n; ++i)
 {
  for (j=i+1; j<n; ++j)
  {
   if (number[i] < number[j])
   {
    a        = number[i];
    number[i] = number[j];
    number[j] = a;
   }
  }
 }

 printf ("The numbers arranged in descending order are given belown");
 for (i=0; i<n; ++i)
 {
  printf ("%dn",number[i]);
 }

 printf ("The 2nd largest number is  = %dn", number[1]);
 printf ("The 2nd smallest number is = %dn", number[n-2]);

 ave = (number[1] +number[n-2])/2;
 counter = 0;

 for (i=0; i<n; ++i)
 {
  if (ave == number[i])
  {
   ++counter;
  }
 }
 if (counter == 0 )
  printf ("The average of %d  and %d is = %d is not in the arrayn", number[1], number[n-2], ave);
 else
  printf ("The average of %d  and %d in the array is %d in numbersn",number[1], number[n-2], counter);
}           /* End of main() */
Read more Similar C Programs
Array In C

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C program to accept N numbers and arrange them in an descending order

C Sorting,
C program to accept N numbers and arrange them in an descending order. Program will accept the array of elements, and returns the elements in descending order. Program use the Bubble sort Technique to sort the Array. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>

void main ()
{
int i,j,a,n,number[30];

printf ("Enter the value of Nn");
scanf ("%d", &n);

printf ("Enter the numbers n");
for (i=0; i<n; ++i)
scanf ("%d",&number[i]);

for (i=0; i<n; ++i)
{
for (j=i+1; j<n; ++j)
{
if (number[i] < number[j])
{
a= number[i];
number[i] = number[j];
number[j] = a;
}
}
}

printf ("The numbers arrenged in descending order are given belown");
for (i=0; i<n; ++i)
printf ("%dn",number[i]);
} /* End of main() */
Read more Similar C Programs
Array In C

Sorting Techniques

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to multiply given number by 4 using bitwise operators

C Program to multiply given number by 4 using bitwise operators. Bitwise operators allows to cahnge or edit the specific bits within an integer. Program will multiply a given number by 4 using left shift(<<) bitwise operator. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

/* c program to multiply given number by 4 *
* using bitwise operators */

#include <stdio.h>

void main()
{
long number, tempnum;

printf("Enter an integern");
scanf("%ld",&number);
tempnum = number;
number = number << 2; /*left shift by two bits*/

printf("%ld x 4 = %ldn", tempnum,number);
}
Read more Similar C Programs
Array In C

Sorting Techniques

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to check if a given matrix is an identity matrix

C Program to check if a given matrix is an identity matrix or not. If I is theIdentity Matrix,then for any matrix A, IA=AI=A. Program will check the givan matrix is identity or not, and prints the appropriate message. Read more about C Programming Language .

–>

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
/* C Program Write a C Program to check if a given matrix is an identity matrix */
#include <stdio.h>

void main()
{
int A[10][10];
int i, j, R, C, flag =1;

printf("Enter the order of the matrix An");
scanf("%d %d", &R, &C);

printf("Enter the elements of matrix An");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
scanf("%d",&A[i][j]);
}
}
printf("MATRIX A isn");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
printf("%3d",A[i][j]);
}
printf("n");
}

/* Check for unit (or identity) matrix */

for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
if((A[i][i] != 1) || (( i != j) && (A[i][j] != 0)))
{
flag = 0;
break;
}
}
}

if(flag == 1 )
printf("It is identity matrixn");
else
printf("It is not a identity matrixn");
}
Read more Similar C Programs
Matrix Programs
Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

–>

(c) www.c-program-example.com

C Program to accept two matrices and check if they are equal

C Program to accept two matrices and check if they are equal or not?. Program will accept the two matrices, and return true if their order and their elements are equal, i.e. for all , if a[i][j]==b[i][j]. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

/* Write a C Program to accept two matrices and check if they are equal */

#include <stdio.h>
#include <stdlib.h>

void main()
{
int A[10][10], B[10][10];
int i, j, R1, C1, R2, C2, flag =1;

printf("Enter the order of the matrix An");
scanf("%d %d", &R1, &C1);

printf("Enter the order of the matrix Bn");
scanf("%d %d", &R2,&C2);

printf("Enter the elements of matrix An");
for(i=0; i<R1; i++)
{
for(j=0; j<C1; j++)
{
scanf("%d",&A[i][j]);
}
}

printf("Enter the elements of matrix Bn");
for(i=0; i<R2; i++)
{
for(j=0; j<C2; j++)
{
scanf("%d",&B[i][j]);
}
}

printf("MATRIX A isn");
for(i=0; i<R1; i++)
{
for(j=0; j<C1; j++)
{
printf("%3d",A[i][j]);
}
printf("n");
}

printf("MATRIX B isn");
for(i=0; i<R2; i++)
{
for(j=0; j<C2; j++)
{
printf("%3d",B[i][j]);
}
printf("n");
}

/* Comparing two matrices for equality */

if(R1 == R2 && C1 == C2)
{
printf("Matrices can be comparedn");
for(i=0; i<R1; i++)
{
for(j=0; j<C2; j++)
{
if(A[i][j] != B[i][j])
{
flag = 0;
break;
}
}
}
}
else
{ printf(" Cannot be comparedn");
exit(1);
}

if(flag == 1 )
printf("Two matrices are equaln");
else
printf("But,two matrices are not equaln");

}
Read more Similar C Programs
Matrix Programs
Learn C Programming

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com