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

C Program To Compute X ^ N

C program to compute the value of X ^ N, given X and N as inputs. Program accepts two integers x, n and computes the power of x to the n by using recursion function power().  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>
#include <math.h>

void main()
{
long int x,n,xpown;
long int power(int x, int n);

printf("Enter the values of X and Nn");
scanf("%ld %ld",&x,&n);

xpown = power (x,n);

printf(" %d to the power %d = %ldn",x,n,xpown);
}

/*Recursive function to computer the X to power N*/

long int power(int x, int n)
{
if (n==1)
return(x);
else if ( n%2 == 0)
return (pow(power(x,n/2),2)); /*if n is even*/
else
return (x*power(x, n-1)); /* if n is odd*/
}
Read more Similar C Programs
Learn C Programming
Recursion
Number System

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 convert days to years, weeks and days

Write a C Program to convert given number of days to a measure of time given in years, weeks and days. For example 375 days is equal to 1 year 1 week and 3 days (ignore leap year).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>
#define DAYSINWEEK 7

void main()
{
int ndays, year, week, days;

printf("Enter the number of daysn");
scanf("%d",&ndays);

year = ndays/365;
week = (ndays % 365)/DAYSINWEEK;
days = (ndays%365) % DAYSINWEEK;

printf ("%d is equivalent to %d years, %d weeks and %d daysn",
ndays, year, week, days);
}
Read more Similar C Programs
Searching in C

C Strings

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 compute the surface area and volume of a cube

C Program to compute the surface area and volume of a cube. Program will accept the length of the sides and calculates surface area and volume of the cube. 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>
#include <math.h>

void main()
{
float side, surfArea, volume;

printf("Enter the length of a siden");
scanf("%f", &side);

surfArea = 6.0 * side * side;

volume = pow (side, 3);

printf("Surface area = %6.2f and Volume = %6.2fn", surfArea, volume);
}
Read more Similar C Programs
Learn C Programming

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