Chapter:
Arrays-
1. Write a C program to find determinant of n*n matrix.
#includeint main(){ float matrix[10][10], ratio, det; int i, j, k, n; printf("Enter order of matrix: "); fflush(stdout); scanf("%d", &n); printf("Enter the matrix: \n"); for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ fflush(stdout); scanf("%f", &matrix[i][j]); } } /* Conversion of matrix to upper triangular */ for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ if(j>i){ ratio = matrix[j][i]/matrix[i][i]; for(k = 0; k < n; k++){ matrix[j][k] -= ratio * matrix[i][k]; } } } } det = 1; //storage for determinant for(i = 0; i < n; i++) det *= matrix[i][i]; printf("The determinant of matrix is: %.2f\n\n", det); return 0; }
2. Write a program in C to find maximum and minimum element in an array.
#includevoid main() { int arr1[100]; int i, mx, mn, n; printf("\n\nFind maximum and minimum element in an array :\n"); printf("--------------------------------------------------\n"); printf("Input the number of elements to be stored in the array :"); fflush(stdout); scanf("%d",&n); printf("Input %d elements in the array :\n",n); for(i=0;i mx) { mx = arr1[i]; } if(arr1[i]
3. Write a program in C to sort elements of an array in descending order.
4. Write a program in C for multiplication of two square Matrices.
#includevoid enterData(int first[][10], int second[][10], int r1, int c1, int r2, int c2); void multiplyMatrices(int first[][10], int second[][10], int multResult[][10], int r1, int c1, int r2, int c2); void display(int mult[][10], int r1, int c2); int main() { int first[10][10], second[10][10], mult[10][10], r1, c1, r2, c2; printf("Enter rows and column for the first matrix: "); fflush(stdout); scanf("%d %d", &r1, &c1); printf("Enter rows and column for the second matrix: "); fflush(stdout); scanf("%d %d", &r2, &c2); // Taking input until columns of the first matrix is equal to the rows of the second matrix while (c1 != r2) { printf("Error! Enter rows and columns again.\n"); printf("Enter rows and columns for the first matrix: "); fflush(stdout); scanf("%d%d", &r1, &c1); printf("Enter rows and columns for the second matrix: "); fflush(stdout); scanf("%d%d", &r2, &c2); } // Function to take matrices data enterData(first, second, r1, c1, r2, c2); // Function to multiply two matrices. multiplyMatrices(first, second, mult, r1, c1, r2, c2); // Function to display resultant matrix after multiplication. display(mult, r1, c2); return 0; } void enterData(int first[][10], int second[][10], int r1, int c1, int r2, int c2) { printf("\nEnter elements of matrix 1:\n"); for (int i = 0; i < r1; ++i) { for (int j = 0; j < c1; ++j) { printf("Enter a%d%d: ", i + 1, j + 1); scanf("%d", &first[i][j]); } } printf("\nEnter elements of matrix 2:\n"); for (int i = 0; i < r2; ++i) { for (int j = 0; j < c2; ++j) { printf("Enter b%d%d: ", i + 1, j + 1); scanf("%d", &second[i][j]); } } } void multiplyMatrices(int first[][10], int second[][10], int mult[][10], int r1, int c1, int r2, int c2) { // Initializing elements of matrix mult to 0. for (int i = 0; i < r1; ++i) { for (int j = 0; j < c2; ++j) { mult[i][j] = 0; } } // Multiplying first and second matrices and storing in mult. for (int i = 0; i < r1; ++i) { for (int j = 0; j < c2; ++j) { for (int k = 0; k < c1; ++k) { mult[i][j] += first[i][k] * second[k][j]; } } } } void display(int mult[][10], int r1, int c2) { printf("\nOutput Matrix:\n"); for (int i = 0; i < r1; ++i) { for (int j = 0; j < c2; ++j) { printf("%d ", mult[i][j]); if (j == c2 - 1) printf("\n"); } } }
5. Write a program in C to insert New value in array.
#includevoid main() { int arr1[100],i,n,p,x; printf("\n\nInsert New value in the unsorted array : \n "); printf("-----------------------------------------\n"); printf("Input the size of array : "); fflush(stdout); scanf("%d", &n); /* Stored values into the array*/ printf("Input %d elements in the array in ascending order:\n",n); for(i=0;i =p;i--) { arr1[i]= arr1[i-1]; } /* insert value at given position */ arr1[p-1]=x; printf("\n\nAfter Insert the element the new list is :\n"); for(i=0;i<=n;i++) printf("% 5d",arr1[i]); printf("\n\n"); }
Insert New value in the unsorted array :
-----------------------------------------
Input the size of array : 4
Input 4 elements in the array in ascending order:
element - 0 : 1
element - 1 : 8
element - 2 : 7
element - 3 : 10
Input the value to be inserted : 5
Input the Position, where the value to be inserted :2
The current list of the array :
1 8 7 10
After Insert the element the new list is :
1 5 8 7 10 6. Write a C Program to Add Two Matrices Using Multi-dimensional Arrays.
#includeint main() { int r, c, a[100][100], b[100][100], sum[100][100], i, j; printf("Enter the number of rows (between 1 and 100): "); fflush(stdout); scanf("%d", &r); printf("Enter the number of columns (between 1 and 100): "); fflush(stdout); scanf("%d", &c); printf("\nEnter elements of 1st matrix:\n"); for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { printf("Enter element a%d%d: ", i + 1, j + 1); fflush(stdout); scanf("%d", &a[i][j]); } } printf("Enter elements of 2nd matrix:\n"); for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { printf("Enter element a%d%d: ", i + 1, j + 1); fflush(stdout); scanf("%d", &b[i][j]); } } // adding two matrices for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { sum[i][j] = a[i][j] + b[i][j]; } } // printing the result printf("\nSum of two matrices: \n"); for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { printf("%d ", sum[i][j]); if (j == c - 1) { printf("\n\n"); } } } return 0; }
7. Write a program in C to delete an element at desired position from an array.
#includevoid main() { int arr1[50],i,pos,n; printf("\n\nDelete an element at desired position from an array :\n"); printf("---------------------------------------------------------\n"); printf("Input the size of array : "); fflush(stdout); scanf("%d", &n); /* Stored values into the array*/ printf("Input %d elements in the array in ascending order:\n",n); for(i=0;i Output:
Delete an element at desired position from an array : --------------------------------------------------------- Input the size of array : 5 Input 5 elements in the array in ascending order: element - 0 : 1 element - 1 : 2 element - 2 : 3 element - 3 : 4 element - 4 : 5 Input the position where to delete: 3 The new list is : 1 2 4 5
8. Write a C program to find transpose of a matrix.
#includeint main() { int a[10][10], transpose[10][10], r, c, i, j; printf("Enter rows and columns: "); fflush(stdout); scanf("%d %d", &r, &c); // Assigning elements to the matrix printf("\nEnter matrix elements:\n"); for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { printf("Enter element a%d%d: ", i + 1, j + 1); fflush(stdout); scanf("%d", &a[i][j]); } } // Displaying the matrix a[][] printf("\nEntered matrix: \n"); for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { printf("%d ", a[i][j]); if (j == c - 1) { printf("\n"); } } } // Finding the transpose of matrix a for (i = 0; i < r; ++i) { for (j = 0; j < c; ++j) { transpose[j][i] = a[i][j]; } } // Displaying the transpose of matrix a printf("\nTranspose of the matrix:\n"); for (i = 0; i < c; ++i) { for (j = 0; j < r; ++j) { printf("%d ", transpose[i][j]); if (j == r - 1) { printf("\n"); } } } return 0; }
9. Write a program in C to sort elements of an array in ascending order.
10. Write a program in C to separate odd and even integers in separate arrays.
All Chapters
View all Chapter and number of question available From each chapter from C-programming-
C Programs on integers
C Programs with explanation and detailed solution and output for practising and improving your coding skills, suitable for any level learner..
C programs on various integers
C programming tutorials Coming soon...
Learn and master the C Programming concepts with IOEBOOSTER, suitable for both beginners and intermediate level students as per IOE and POU syllabus.These c programming tutorials are completely free and important for exam point of view and for mast..
Recursive program in c
Recursion in computer science is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem. Such problems can generally be solved by iteration, but this needs to identify and index the smaller instances at programming time.
Arrays
- c programms on arrays
- complete IOE solution on arrays
- Detailed description
- And much more
Strings in C programming
- c programms on Strings
- complete IOE solution on Strings
- Detailed description
- Each one using pointer Concepts
- And much more
Data Files
- C programming concepts of data files and data structures
- IOE C Programming Solutions
- Important Numerous C Program
Pattern Printing in C
Learn to print half pyramid, pyramid, inverted pyramid, Pascal's Triangle Floyd's triangle and various pattern in C Programming using control statements. This helps you to build up your logic towards C Programming Problems.
Topics
This Chapter Arrays- consists of the following topics
Guest