Write a C program to find the biggest(maximum)of n number using arrays.
#include <stdio.h>
int main() {
int n, i, max;
// Input: Read the number of elements
printf("Enter the number of elements: ");
scanf("%d", &n);
// Declare the array to store the numbers
int numbers[n];
// Input: Read the elements into the array
printf("Enter %d numbers:\n", n);
for(i = 0; i < n; i++) {
scanf("%d", &numbers[i]);
// Initialize the first element as the maximum
max = numbers[0];
// Find the maximum number in the array
for(i = 1; i < n; i++) {
if(numbers[i] > max) {
max = numbers[i];
// Output: Display the maximum number
printf("The largest number is: %d\n", max);
return 0;
Output:
Enter the number of elements: 5
Enter 5 numbers:
3 12 7 19 5
The largest number is: 19
Construct a C program to sort elements in ascending order in an array
#include <stdio.h>
int main() {
int n, i, j, temp;
// Input: Read the number of elements
printf("Enter the number of elements: ");
scanf("%d", &n);
// Declare the array to store the elements
int arr[n];
// Input: Read the elements into the array
printf("Enter %d numbers:\n", n);
for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
// Sorting the array using Bubble Sort
for(i = 0; i < n - 1; i++) {
for(j = 0; j < n - i - 1; j++) {
// Swap if the current element is greater than the next element
if(arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
// Output: Display the sorted array
printf("Array in ascending order:\n");
for(i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
Output:
Enter the number of elements: 5
Enter 5 numbers:
34 12 56 23 1
Array in ascending order: 1 12 23 34 56
Write a C program to find Transpose of a given matrix
#include <stdio.h>
int main() {
int rows, cols, i, j;
// Input: Read the number of rows and columns of the matrix
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);
// Declare the matrix and its transpose
int matrix[rows][cols], transpose[cols][rows];
// Input: Read the elements of the matrix
printf("Enter the elements of the matrix:\n");
for(i = 0; i < rows; i++)
for(j = 0; j < cols; j++)
scanf("%d", &matrix[i][j]);
// Find the transpose of the matrix
for(i = 0; i < rows; i++) {
for(j = 0; j < cols; j++) {
transpose[j][i] = matrix[i][j]; // Swap rows and columns
// Output: Display the original matrix
printf("Original Matrix:\n");
for(i = 0; i < rows; i++) {
for(j = 0; j < cols; j++) {
printf("%d ", matrix[i][j]);
printf("\n");
// Output: Display the transpose of the matrix
printf("Transpose of the Matrix:\n");
for(i = 0; i < cols; i++) {
for(j = 0; j < rows; j++) {
printf("%d ", transpose[i][j]);
printf("\n");
return 0;
Ouput:
Enter the number of rows: 2
Enter the number of columns: 3
Enter the elements of the matrix:
123
456
Original Matrix:
123
456
Transpose of the Matrix:
14
25
36
Write a C program to perform addition of two matrices in 2D array.
#include <stdio.h>
int main() {
int rows, cols, i, j;
// Input: Read the number of rows and columns of the matrices
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);
// Declare the matrices and result matrix
int matrix1[rows][cols], matrix2[rows][cols], result[rows][cols];
// Input: Read the elements of the first matrix
printf("Enter the elements of the first matrix:\n");
for(i = 0; i < rows; i++) {
for(j = 0; j < cols; j++) {
scanf("%d", &matrix1[i][j]);
// Input: Read the elements of the second matrix
printf("Enter the elements of the second matrix:\n");
for(i = 0; i < rows; i++)
{
for(j = 0; j < cols; j++)
scanf("%d", &matrix2[i][j]);
// Perform the addition of the two matrices
for(i = 0; i < rows; i++) {
for(j = 0; j < cols; j++) {
result[i][j] = matrix1[i][j] + matrix2[i][j];
// Output: Display the sum of the matrices
printf("Sum of the two matrices:\n");
for(i = 0; i < rows; i++)
for(j = 0; j < cols; j++)
printf("%d ", result[i][j]);
printf("\n");
return 0;
Output:
Enter the number of rows: 2
Enter the number of columns: 3
Enter the elements of the first matrix:
123
456
Enter the elements of the second matrix:
654
321
Sum of the two matrices:
777
777