C program to find sum of main diagonal elements of a matrix

Write a C program to read elements in a matrix and find the sum of main diagonal (major diagonal) elements of matrix. Find sum of all elements of main diagonal of a matrix. Logic to find sum of main diagonal elements of a matrix in C programming.

Example

Input

Input array elements: 
1 2 3
4 5 6
7 8 9

Output

Sum of main diagonal elements = 15

Read more

C program to check whether two matrices are equal or not

Write a C program to enter elements in two matrices and check whether both matrices are equal or not. C program to check whether elements of two matrices are equal or not. Logic to check if two matrices are equal or not in C programming.

Example

Input

Input elements of matrix1:
1 2 3
4 5 6
7 8 9

Input elements of matrix2:
1 2 3
4 5 6
7 8 9

Output

Both matrices are equal

Read more

C program to multiply two matrices

Write a C program to read elements in two matrices and multiply them. Matrix multiplication program in C. How to multiply matrices in C. Logic to multiply two matrices in C programming.

Example

Input

Input elements of matrix1:
1 2 3
4 5 6
7 8 9
Input elements of matrix2:
9 8 7
6 5 4
3 2 1

Output

Product of matrices =
30 24 18
84 69 54
138 114 90

Read more

C program to perform Scalar matrix multiplication

Write a C program to read elements in a matrix and perform scalar multiplication of matrix. C program for scalar multiplication of matrix. How to perform scalar matrix multiplication in C programming. Logic to perform scalar matrix multiplication in C program. Example Input Input elements of matrix A: 1 2 3 4 5 6 7 … Read more

C program to subtract two matrices

Write a C program to read elements in two matrices and find the difference of two matrices. Program to subtract two matrices in C. Logic to subtract two matrices in C programming.

Example

Input

Input elements in 3x3 matrix1:
1 2 3
4 5 6
7 8 9

Input elements in 3x3 matrix2:
9 8 7
6 5 4
3 2 1

Output

Difference of both matrices =
-8 -6 -4
-2  0  2
4  6  8

Read more

C program to add two matrices

Write a C program to read elements in two matrices and add elements of both matrices. C program for addition of two matrix. Matrix addition program in C. Logic to add two matrix in C programming.

Example

Input

Input elements in 3x3 matrix1: 
1 2 3
4 5 6
7 8 9
Input elements in 3x3 matrix2:
9 8 7
6 5 4
3 2 1

Output

Sum of both matrix =
10 10 10
10 10 10
10 10 10

Read more

C program to print all unique elements in array

Write a C program to input elements in array and print all unique elements in array. How to find unique elements in array in C programming. Logic to find unique elements in array in C program.

Array unique elements

Example

Input

Input array elements: 1, 2, 3, 5, 1, 5, 20, 2, 12, 10

Output

All unique elements in the array are: 3, 20, 12, 10

Read more

Array and Matrix programming exercises and solutions in C

Array is a linear data structure that hold finite sequential collection of homogeneous data. We can store a collection of values in an array.

Array uses an integer value index to access a specific element. Index starts from 0 and goes till N-1 (where N is the size of array).

Read more

C program to sort array in ascending or descending order

Write a C program to input elements in array and sort array elements in ascending or descending order. How to sort array in ascending order in C programming. Logic to sort array in ascending or descending order.

Example

Input

Input size of array: 10
Input array elements: 20, 2, 10, 6, 52, 31, 0, 45, 79, 40

Output

Array sorted in ascending order: 0, 2, 6, 10, 20, 31, 40, 45, 52, 79

Read more

C program to search element in an array

Write a C program to input elements in array and search whether an element exists in array or not. How to search element in array linearly in C programming. Logic to search element in array sequentially in C program.

Example

Input

Input size of array: 10
Input elements in array: 10, 12, 20, 25, 13, 10, 9, 40, 60, 5

Output

Element to search is: 25
Element found at index 3

Read more