C program to find the transpose of a given Matrix.

Write a C program to read A (MxN), find the transpose of a given matrix and output both the input matrix and the transposed matrix.
Transpose of a matrix is the interchanging the rows and columns, If A is matrix of order(i*j), where i is the row and j is the column, then Transpose of A is A(j*i). 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 <conio.h>

void main()
{
int i,j,M,N;
int A[10][10], B[10][10];

int transpose(int A[][10], int r, int c); /*Function prototype*/

clrscr();

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

printf("Enter the elements of matrixn");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
scanf("%d",&A[i][j]);
}
}

printf("Matrix A isn");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
printf("%3d",A[i][j]);
}
printf("n");
}

/* Finding Transpose of matrix*/
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
B[i][j] = A[j][i];
}
}

printf("Its Transpose isn");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
printf("%3d",B[i][j]);
}
printf("n");
}

} /*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 Matrix addition,Subtraction and trace.

Write a C program to read two matrices A (MxN) and B(MxN) and perform addition ,subtraction of A and B, and Find the trace of the resultant matrix. Output the given matrix, their sum or Differences and the trace. 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 <conio.h>

void main()
{
int A[10][10], B[10][10], sumat[10][10], diffmat[10][10];
int i, j, M,N, option;

void trace (int arr[][10], int M, int N);

clrscr();

printf("Enter the order of the matrice A and Bn");
scanf("%d %d", &M, &N);

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

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

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

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

printf("Enter your option: 1 for Addition and 2 for Subtractionn");
scanf("%d",&option);

switch (option)
{
case 1: for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
sumat[i][j] = A[i][j] + B[i][j];
}
}

printf("Sum matrix isn");
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
printf("%3d",sumat[i][j]) ;
}
printf("n");
}

trace (sumat, M, N);
break;

case 2:for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
diffmat[i][j] = A[i][j] - B[i][j];
}
}

printf("Difference matrix isn");
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
printf("%3d",diffmat[i][j]) ;
}
printf("n");
}

trace (diffmat, M, N);
break;
}

} /* End of main() */

/*Function to find the trace of a given matrix and print it*/

void trace (int arr[][10], int M, int N)
{
int i, j, trace = 0;
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
if (i==j)
{
trace = trace + arr[i][j];
}
}
}
printf ("Trace of the resultant matrix is = %dn", trace);

}
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 evaluate the given polynomial P(x)=AnXn + An-1Xn-1 + An-2Xn-2+… +A1X + A0, by reading its coefficents into an array.

Write a C program to evaluate the given polynomial P(x)=AnXn + An-1Xn-1 + An-2Xn-2+… +A1X + A0, by reading its coefficents into an array.A Polynomial is a mathematical expression involving a sum of powers in one or more variables multiplied by coefficients. 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 <conio.h>
#include <stdlib.h>
#define MAXSIZE 10

voidmain()
{
int a[MAXSIZE];
int i, N,power;
float x, polySum;

clrscr();

printf("Enter the order of the polynomialn");
scanf("%d", &N);

printf("Enter the value of xn");
scanf("%f", &x);

/*Read the coefficients into an array*/

printf("Enter %d coefficientsn",N+1);
for (i=0;i <= N;i++)
{
scanf("%d",&a[i]);
}

polySum = a[0];

for (i=1;i<= N;i++)
{
polySum = polySum * x + a[i];
}

power = N;

/*power--;*/

printf("Given polynomial is:n");
for (i=0;i<= N;i++)
{
if (power < 0)
{
break;
}

/* printing proper polynomial function*/
if (a[i] > 0)
printf(" + ");
else if (a[i] < 0)
printf(" - ");
else
printf (" ");
printf("%dx^%d ",abs(a[i]),power--);

}

printf("nSum of the polynomial = %6.2fn",polySum);
}

Array In C Simple C ProgramsYou 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 average of largest two of the given numbers in the array.

Example programs to solve the problems of Arrays in C.
Write a C program to read in four integer numbers into an array and find the average of largest two of the given numbers without sorting the array. The program should output the given four numbers and the average with suitable headings. 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 <conio.h>
#define MAX 4

void main()
{
int a[MAX], i, l1,l2,temp;

clrscr();

printf("Enter %d integer numbersn", MAX);
for (i=0; i < MAX; i++)
{
scanf("%d", &a[i]);
}

printf("Input interger aren");
for (i=0; i < MAX; i++)
{
printf("%5d", a[i]);
}

printf("n");

l1 = a[0]; /*assume first element of array is the first largest*/
l2 = a[1]; /*assume first element of array is the second largest*/

if (l1 < l2)
{
temp = l1;
l1 = l2;
l2 = temp;
}

for (i=2;i<4;i++)
{
if (a[i] >= l1)
{
l2 = l1;
l1 = a[i];
}
else if(a[i] > l2)
{
l2= a[i];
}
}

printf("n%d is the first largestn", l1);
printf("%d is the second largestn", l2);
printf("nAverage of %d and %d = %dn", l1,l2, (l1+l2)/2);

}
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 Demonstrate Linear search

Write a C program to input N numbers (integers or reals) and store them in an array. Conduct a linear search for a given key number and report success or failure in the form of a suitable message.
Linear search is the basic searching algorithm, also called as sequential search. Algorithm search’s the element by comparing the each element in the list, until the desired element found. 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 <conio.h>

void main()
{
int array[10];
int i, N, keynum, found=0;

clrscr();

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

printf("Enter the elements one by onen");
for(i=0; i<N ; i++)
{
scanf("%d",&array[i]);
}
printf("Input array isn");
for(i=0; i<N ; i++)
{
printf("%dn",array[i]);
}
printf("Enter the element to be searchedn");
scanf("%d", &keynum);

/* Linear search begins */
for ( i=0; i < N ; i++)
{
if( keynum == array[i] )
{
found = 1;
break;
}
}
if ( found == 1)
printf("SUCCESSFUL SEARCHn");
else
printf("Search is FAILEDn");

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

Search Algorithms.

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 value of sin(x)

Write a C program to find the value of sin(x) using the series up to the given accuracy (without using user defined function) Also print sin(x) using library function. 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 <conio.h>
#include <math.h>
#include <stdlib.h>

void main()
{
 int n, x1;
 float  acc, term, den, x, sinx=0, sinval;

 clrscr();

 printf("Enter the value of x (in degrees)n");
 scanf("%f",&x);

 x1 = x;

 /* Converting degrees to radians*/

 x = x*(3.142/180.0);
 sinval = sin(x);

 printf("Enter the accuary for the resultn");
 scanf("%f", &acc);

 term = x;
 sinx = term;
 n = 1;

 do
 {
  den = 2*n*(2*n+1);
  term = -term * x * x / den;
  sinx = sinx + term;
  n = n + 1;

 } while(acc <= fabs(sinval - sinx));

 printf("Sum of the sine series         = %fn", sinx);
 printf("Using Library function sin(%d) = %fn", x1,sin(x));

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

Search Algorithms.

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 sum of ‘N’ natural numbers.

Write a C program to find the sum of ‘N’ natural numbers. Natural numbers are the whole numbers except zero, usually we used for counting.
Example:1, 2, 3, 4,———– 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 <conio.h>

void main()
{
int i, N, sum = 0;

clrscr();

printf("Enter an integer numbern");
scanf ("%d", &N);

for (i=1; i <= N; i++)
{
sum = sum + i;
}

printf ("Sum of first %d natural numbers = %dn", N, sum);
}
Read more Similar C Programs
Searching in C

Number Theory 
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 check whether a given integer number is positive or negative.

Write a C program to check whether a given integer number is positive or negative.Read more about C Programming Language . This program is available on GitHub https://github.com/snadahalli/cprograms/blob/master/posneg.c

/***********************************************************
* 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 <conio.h>

void main()
{
int number;
clrscr();

printf("Enter a numbern");
scanf ("%d", &number);

if (number > 0)
printf ("%d is a positive numbern", number);
else if (number < 0)
printf ("%d is a negative numbern", number);
else
printf("You entered 0n");

}
Read more Similar C Programs
Searching in C

Number Theory 
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 check whether a given integer is odd or even.

Write a C program to check whether a given integer is odd or even.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 <conio.h>

void main()
{
int ival, remainder;

clrscr();

printf("Enter an integer :");
scanf ("%d", &ival);

remainder = ival % 2;

if (remainder == 0)
printf ("%d, is an even integern", ival);
else
printf ("%d, is an odd integern", ival);

}
Read more Similar C Programs
Searching in C

Number Theory 
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 Swap Two Variables

C Program To Swap Two Variables without using the third variable. This type of C programs are asked in various Interviews.There are various methods to achieve this one. For example, a=a+b;
b=a-b;
a=a-b;
Here we use the XOR(^) operator to Swap Two Variables without using the third 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>

int main()
{
int a=20;
int b=10;
printf("Values of a and b before swappingn");
printf("a=%dnb=%dn",a,b);
a=a^b;
b=b^a;
a=b^a;
printf("Values of a and b After swappingn");
printf("a=%dnb=%dn",a,b);
return 0;
}
Read more Similar C Programs
C Interview Questions

Number Theory 
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