Skip to main content

Posts

C Program to find the sum of two numbers using user-defined function.

 C Program to find the sum of two numbers using user-defined function.          In this example, we will calculate the sum of to numbers using user-defined function.  Here in the output we have taked two numbers 23 and 65 which after calculation gives 88. PROGRAM #include <stdio.h> #include <conio.h> int   sum ( int   a , int   b ); void   main () {      int  x,y,res= 0 ;      printf ( "Enter the values of x and y :" );      scanf ( " %d%d " ,&x,&y);     res= sum (x,y);      printf ( "The sum is :  %d " ,res);      getch (); } int   sum ( int   a , int   b ) {      return (a+b); } OUTPUT Enter the values of x and y :23 65 The sum is : 88 NOTE:   You Can Comment Your Code if you have solved d...

C Program to find the sum of the series 1^2+2^2+3^2+…..+n^2

C Program to find the sum of the series  1 2 +2 2 +3 2 +…..+n 2 Enter the end limit at the runtime.       In this example, we calculate the sum of the above mentioned series till the end-limit entered by the user. We have used built-in function pow(x,y) to find the power of the given number.     Here in the output we have entered the value of end-limit as number 7 which gives a sum of 140.    PROGRAM #include <stdio.h> #include <math.h> #include <conio.h> void   main () {      int  n,sum= 0 ,i;      printf ( "Enter the end limit :" );      scanf ( " %d " ,&n);      for (i= 1 ;i<=n;i++)     {         sum=sum+ pow (i, 2 );     }      printf ( "Sum of the series is :  %d " ,sum);  ...

C Program to Swap the values of two variables using function.

C Program to Swap the values of two variables using function.     In this example, we swap the values of two variables using function. We have declared a function swap. PROGRAM #include <stdio.h> #include <conio.h> void   swap ( int *, int  *); int   main () {      int   a , b ;      printf ( "Enter the values of a and b : " );      scanf ( " %d%d " ,& a ,& b );      printf ( "Before swapping the values in main a= %d  , b= %d \n " , a , b );      swap (& a ,& b );      printf ( "After swapping the values in main a= %d  , b= %d \n " , a , b );      getch (); } void   swap ( int  * a , int  * b ) {      int   temp ;    ...

C Program to Multiply two Matrices

 C Program to Multiply two Matrices.     In this example, we will calculate the product of the two matrices allowing the user to enter their required number of rows and columns. In matrix multiplication the number of columns, in the first matrix must be equal to the number of  rows in the second matrix, otherwise multiplication is not possible. The product will have the number of rows of the first matrix and the number of columns of the second matrix.     Here in the output we have taken two matrices of order 2x3 and 3x2. The resulting matrix after calculating the product will be of the order 2x2. PROGRAM #include <stdio.h> #include <conio.h> void   main () {      int   row1 , row2 , column1 , column2 , i , j , k ;      int   a [ 10 ][ 10 ], b [ 10 ][ 10 ], mul [ 10 ][ 10 ];      printf ( "Enter the row size of the 1st Matrix :...

C Program to find the Transpose of a Matrix.

C Program to find the Transpose of  a Matrix.       In this example, we will find the transpose of a given matrix according to the requirements of the row size and column size.      Here in the output we have entered a 3x2 Matrix whose transpose will be 2x3 Matrix. PROGRAM #include <stdio.h> #include <conio.h> int   main () {      int   row , column , i , j , a [ 100 ][ 100 ];      printf ( "Enter the row size of the matrix :" );      scanf ( " %d " ,& row );      printf ( "Enter the column size of the matrix : " );      scanf ( " %d " ,& column );      printf ( "Enter the elements of the matrix : " );      for ( i = 0 ; i < row ; i ++)     {  ...

C Program to Add Two Matrices Using Multi-dimensional Array.

C Program to Add Two Matrices Using Multi-dimensional Array.       In this example, we will add two matrices using multi-dimensional array. Two matrices can be added if they are equal means their order/dimensions must be same. Addition of matrices is performed by adding the corresponding elements of the two matrices.     Here in the Output we have  allowed the user to enter the row and column size of their matrices according to their requirements but they can enter the value of row size and column size less than 100. PROGRAM #include <stdio.h> #include <conio.h> int   main () {      int   row , column , i , j , a [ 100 ][ 100 ], b [ 100 ][ 100 ], c [ 100 ][ 100 ];      printf ( "Enter the row size of the matrices(max. value 100) : " );      scanf ( " %d " ,& row );      printf ( "Enter the co...