Skip to main content

Posts

Showing posts with the label Array

Matrix Addition and subtraction program in C language

  Matrix Addition and Subtraction program in C language Today here you will be able to learn about multiple tasks in Matrix-like addition, subtraction, and multiplication. @#1.Matrix Addition   Suppose that we have two matrices of 3X3 orders. This matrix A and B. In this program   C is the addition of A & B; i and k are used for initialization. Matrix Addition Program  #include"stdio.h" int main() { int A[10][10],B[10][10],C[10][10],i,k,row,col; printf("Enter The Matrix row & col = "); scanf("%d %d",&row,&col); printf("Enter the First matrix :\n"); for(i=0;i<row;i++) { for (k=0;k<col;k++) { printf("Enter matrix[%d][%d]=",i,k); scanf("%d",&A[i][k]); } } printf("First matrix are:\n"); for(i=0;i<row;i++) { for (k=0;k<col;k++) { printf("%d\t",A[i][k]); } printf("\n"); } printf("Enter the Second matrix :\n"); for(i=0;i<row;i++) { for (k=0;k<col;k++)

Matrix program or 2D Array in C language Transpose of Matrix program in C language

 Matrix program or 2D Array in C language  In C language ,A two dimensional array is also known as matrix .Today we will learn about Matrix  .We all know that we also use loop to define an array .We will create a matrix program using a nested for loop. 1.Matrix program in C language: /*MATRIX PROGRAM*/ #include"stdio.h" int main() { int a[10][10]; int r,c,k,l; printf("ENTER THE ROW AND COL:"); scanf("%d %d",&r,&c); printf("ENTER THE MATRIX ELEMENTS:"); for(k=0;k<r;k++) { for(l=0;l<c;l++) { printf("ENTER a[%d][%d] : ",k,l); scanf("%d",&a[k][l]); } } printf("MATRIX ARE: \n"); for(k=0;k<r;k++) { for(l=0;l<c;l++) { printf("%d\t",a[k][l]); } printf("\n"); } } Output are: ENTER THE ROW AND COL:2 3 ENTER THE MATRIX ELEMENTS:ENTER a[0][0] : 2 ENTER a[0][1] : 5 ENTER a[0][2] : 7 ENTER a[1][0] : 8 ENTER a[1][1] : 6 ENTER a[1][2] : 1 MATRIX ARE: 2

Two dimensional array in C language or matrix program in c language

 Two dimensional arrays: 1.Two dimensional array is known as matrix. 2.An array with two subscripts is termed as two-dimensional array. 3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements. The syntax of declaring a two-dimensional array is : Data-type array name[row][column]; For reading value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { scanf("%d",&a[k][l]); } } For displaying value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { printf("%d",a[k][l]); } printf("\n"); } Simple Matrix Program : #include"stdio.h" int main() { int a[3][3]; int k,l; printf("Enter the array elements: \n"); for(k=0;k<3;k++)  //for reading value// { for(l=0;l<3;l++) { printf("Enter a[%d][%d] :",k,l); scanf("%d",&a[k][l]); } } printf("\n\nMatrix are: \n"); for(k=0;k<3;k++)  //for displaying value

One dimensional array declaration in c language basic of array

One D array **Definition of array** Array can be define as a collection of data object which are stored in consecutive memory location with a common variable name.                                                                                                        or  Array is the collection of similar data types or collection of similar entity stored in contiguous memory location . **Initialization of array** Array can be made initialization at the time of declaration itself. The general form of array initialization is as below  1.Data type array name[size] 2. Data type array name[size]={element1,element2,element3,.....} Example: int a[[4]={1,5,8,4} char d[3]={'A','R',u'} Program #include"stdio.h" int main() { int a[100],i,n; printf("Enter the number of elements : "); scanf("%d",&n); printf("Enter the elements\n"); for(i=0;i<n;i++) { printf("Entre the a[%d] : ",i); scanf("%d",&am

Bubble sort descending order

Bubble sort descending order   #include"stdio.h" int main() { int a[100],n,l,k,swap; printf("Enter the of Elements:"); scanf("%d",&n); for(k=0;k<n;k++) { printf("Enter a[%d] :",k); scanf("%d",&a[k]); } printf("Elements are :\n "); for(k=0;k<n;k++) { printf("%d\t",a[k]); } // sorting // for(k=0;k<n;k++) { for(l=0;l<n;l++) { if(a[l]<a[l+1]) { swap = a[l+1]; a[l+1]= a[l]; a[l]=swap; } } } printf("\nDescending order are:\n"); for(k=0;k<n;k++) { printf("%d \t",a[k]); } } Output are: Enter the of Elements:5 Enter a[0] :12 Enter a[1] :987 Enter a[2] :456 Enter a[3] :320 Enter a[4] :72 Elements are :  12     987     456     320     72 Descending order are: 987     456     320     72      12

Bubble sort ascending order

 Bubble sort ascending order #include"stdio.h" int main() { int a[100],n,l,k,swap; printf("Enter the of Elements:"); scanf("%d",&n); for(k=0;k<n;k++) { printf("Enter a[%d] :",k); scanf("%d",&a[k]); } printf("Elements are :\n "); for(k=0;k<n;k++) { printf("%d\t",a[k]); } // sorting // for(k=0;k<n;k++) { for(l=0;l<n;l++) { if(a[l]>a[l+1]) { swap = a[l+1]; a[l+1]= a[l]; a[l]=swap; } } } printf("\nAscending order are:\n"); for(k=1;k<n+1;k++) { printf("%d \t",a[k]); } } Output are: Enter the of Elements:5 Enter a[0] :12 Enter a[1] :48 Enter a[2] :75 Enter a[3] :16 Enter a[4] :30 Elements are :  12     48      75      16      30 Ascending order are: 12      16      30      48      75