Posts

Let Us C (Chapter 8 : Arrays) : Program-13_3

Image
(3) Write a program to sort a 4 x 4 matrix . // Let Us C (Chapter 8 : Arrays) : Program-13_3 /* (3) Write a program to sort a 4 x 4 matrix. */ #include<stdio.h> #include<conio.h> void main() { int M1[4][4],i,j,k,smallest,temp,*arr; clrscr(); printf("\nProgram to sort elements of a 4x4 Matrix"); printf("\nEnter 4 X 4 matrix"); printf("\nEnter 16 elements of 4x4 Matrix separated by space\n"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%d",&M1[i][j]); } } printf("***** Entered Matrix is *****\n"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { printf("%4d",M1[i][j]); // print matrix } printf("\n"); } arr = M1; // Copy matrix for(i=0;i<15;i++) { for(j=i+1;j<16;j++) { if(*(arr+i) > *(arr+j)) { temp = *(arr + i); *(arr + i) = *(arr + j); *(arr + j) = temp; } } } printf("***** Sorted Matrix is *****\n"); for(i=0;

Let Us C (Chapter 8 : Arrays) : Program-13_2

Image
(2)Write a program to multiply any two 3 x 3 matrices. // Let Us C (Chapter 8 : Arrays) : Program-13_2 /* (2)Write a program to multiply any two 3 x 3 matrices. */ #include<stdio.h> #include<conio.h> void main() { int M1[3][3], M2[3][3], M3[3][3], i,j,k,sum; clrscr(); printf("\nProgram for Multiplication of Matrices"); printf("\nEnter two 3 X 3 matrices"); printf("\nEnter 9 elements of 1st Matrix separated by space\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { //printf(" Enter Element %d : ",M1[i][j]); scanf("%d",&M1[i][j]); } } printf("\nEnter 9 elements of 2nd Matrix separated by space\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { //printf(" Enter Element %d : ",M2[i][j]); scanf("%d",&M2[i][j]); } } printf("***** 1st Matrix *****\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%4d",M1[i][j]); }

Let Us C (Chapter 8 : Arrays) : Program-13_1

Image
(1) Write a program to add two 6 x 6 matrices. // Let Us C (Chapter 8 : Arrays) : Program-13_1 /* (1) Write a program to add two 6 x 6 matrices. */ #include<stdio.h> #include<conio.h> void main() { int M1[6][6], M2[6][6], M3[6][6],i,j,k=1; clrscr(); printf("\nProgram for Addition of Matrices"); printf("\nEnter two 6 X 6 matrices"); printf("\nEnter 36 elements of 1st Matrix separated by space\n"); for(i=0;i<6;i++) { for(j=0;j<6;j++) { scanf("%d",&M1[i][j]); } } printf("\nEnter 36 elements of 2nd Matrix seprated by space\n"); k=1; for(i=0;i<6;i++) { for(j=0;j<6;j++) { //printf(" Enter Element %d : ",k++); scanf("%d",&M2[i][j]); } } printf("***** 1st Matrix *****\n"); for(i=0;i<6;i++) { for(j=0;j<6;j++) { printf("%4d",M1[i][j]); } printf("\n"); } printf("***** 2nd Matrix *****\n")

Let Us C (Chapter 8 : Arrays) : Program-12

Image
Very often in fairs we come across a puzzle that contains 15 numbered square pieces mounted on a frame. These pieces can be moved horizontally or vertically. A possible arrangement of these pieces is shown below:  01      04      15      07  08      10      02      11  14      03      06      13  12      09      05      Blank  As you can see there is a blank at bottom right corner. Implement the following procedure through a program: Draw the boxes as shown above. Display the numbers in the above order. Allow the user to hit any of the arrow keys (up, down, left, or right). If user hits say, right arrow key then the piece with a number 5 should move to the right and blank should replace the original position of 5. Similarly, if down arrow key is hit, then 13 should move down and blank should replace the original position of 13. If left arrow key or up arrow key is hit then no action should be taken. The user would continue hitting the arrow keys till the numbers are not ar

Let Us C (Chapter 8 : Arrays) : Program-11

Image
(k) Write a program to obtain transpose of a 4 x 4 matrix. The transpose of a matrix is obtained by exchanging the elements of each row with the elements of the corresponding column // Let Us C (Chapter 8 : Arrays) : Program-11 /* Write a program to obtain transpose of a 4 x 4 matrix. The transpose of a matrix is obtained by exchanging the elements of each row with the elements of the corresponding column. */ #include<stdio.h> long int Arr[4][4]; unsigned int i,j; void main() { clrscr(); for(i=0;i<4;i++) { for(j=0;j<4;j++) { printf("Enter Arr[%d][%d] element: ",i,j); scanf("%ld",&Arr[i][j]); } } printf("\nMatrix is :\n"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { printf("%0.2ld ",Arr[i][j]); } printf("\n"); } printf("\nTranspose Matrix is: \n"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { printf("%0.2ld ",Arr[j][i]); } printf("\n"); } }

Let Us C (Chapter 8 : Arrays) : Program-10

Image
(j) Write a program to pick up the largest number from any 5 row by 5 column matrix. // Let Us C (Chapter 8 : Arrays) : Program-10 /* Write a program to pick up the largest number from any 5 row by 5 column matrix */ #include<stdio.h> long int Arr[5][5],Largest; unsigned Write a program to pick up the largest number from any 5 row by 5 column matrix. i,j; void main() { clrscr(); printf("Enter 25 elements of 5x5 matrix\n"); for(i=0;i<5;i++) { for(j=0;j<5;j++) { printf("Enter [%d][%d]th element: ",i,j); scanf("%ld",&Arr[i][j]); } } Largest = Arr[0][0]; printf("\nEntered Matrix is : \n"); for(i=0;i<5;i++) { for(j=0;j<5;j++) { printf("%8ld ",Arr[i][j]); if(Largest < Arr[i][j]) Largest = Arr[i][j]; } printf("\n"); } printf("\nLargest element is : %ld",Largest); } OUTPUT

Let Us C (Chapter 8 : Arrays) : Program-9

Image
(i) The screen is divided into 25 rows and 80 columns. The characters that are displayed on the screen are stored in a special memory called VDU memory (not to be confused with ordinary memory). Each character displayed on the screen occupies two bytes in VDU memory. The first of these bytes contains the ASCII value of the character being displayed, whereas, the second byte contains the colour in which the character is displayed. For example, the ASCII value of the character present on zeroth row and zeroth column on the screen is stored at location number 0xB8000000. Therefore the colour of this character would be present at location number 0xB8000000 + 1. Similarly ASCII value of character in row 0, col 1 will be at location 0xB8000000 + 2, and its colour at 0xB8000000 + 3. With this knowledge write a program which when executed would keep converting every capital letter on the screen to small case letter and every small case letter to capital letter. The procedure should stop the mo