C Program to Check whether entered matrix is magic square or not ? What is Magic Square : A magic square is a simple mathematical game developed during the 1500. Square is divided into equal number of rows and columns. Start filling each square with the number from 1 to num ( where num = [...]
C Programs : 2-D Array Programs
C Program to Print Square of Each Element of 2D Array Matrix
C Program : C Program to Print Square of Each Element of 2D Matrix #include<stdio.h> #include<conio.h> #define MAX_ROWS 3 #define MAX_COLS 4 void print_square(int [ ] ); void main (void) { int row; int num [MAX_ROWS][MAX_COLS] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} }; for(row=0; row<MAX_ROWS; row++) print_square(num[row]); } void print_square(int x[ ]) { int col; for [...]
Program to find Transpose of Given Square Matrix
#include<stdio.h> #include<conio.h> void main() { int a[10][10],m,i,j,temp; /* actual size of matrix is m*n i,j - for scanning of array temp - for interchanging of a[i][j] and a[j][i] */ printf(“\n Enter the size of matrix :”); scanf(“%d”,&m); /* Reading elements of matrix */ printf(“\n Enter the values a:”); for(i=0;i<m;i++) for(j=0;j<m;j++) scanf(“%d”,&a[i][j]); //to print original square [...]
C Program to find addition of Lower Triangular Elements in C Programming
#include<stdio.h> #include<conio.h> void main() { int i,j,a[10][10],sum,m,n; /* m - Number of rows n - Number of Columns */ printf(“\nEnter the number of Rows : “); scanf (“%d”,&m); printf(“\nEnter the number of Columns : “); scanf (“%d”,&n); /* Accept the Elements in m x n Matrix */ for( i = 0 ; i < m [...]
C program to calculate sum of Upper Triangular Elements in C
#include< stdio.h> #include< conio.h> void main() { int i,j,a[10][10],sum,m,n; /* m - Number of rows n - Number of Columns */ printf(“\nEnter the number of Rows : “); scanf (“%d”,&m); printf(“\nEnter the number of Columns : “); scanf (“%d”,&n); /* Accept the Elements in m x n Matrix */ for( i = 0 ; i [...]
C Program to evaluate Subtraction of two matrices ( matrix ) in C
#include<stdio.h> #include<conio.h> void main() { int i,j,a[10][10],b[10][10],c[10][10],m1,n1,m2,n2; /* m - Number of rows n - Number of Columns */ clrscr(); printf(“\nEnter the number of Rows of Mat1 : “); scanf (“%d”,&m1); printf(“\nEnter the number of Columns of Mat1 : “); scanf (“%d”,&n1); /* Accept the Elements in m x n Matrix */ for( i = [...]
C program for addition of two matrices in C
#include<stdio.h> #include<conio.h> void main() { int i,j,a[10][10],b[10][10],c[10][10],m1,n1,m2,n2; /* m - Number of rows n - Number of Columns */ clrscr(); printf(“\nEnter the number of Rows of Mat1 : “); scanf (“%d”,&m1); printf(“\nEnter the number of Columns of Mat1 : “); scanf (“%d”,&n1); /* Accept the Elements in m x n Matrix */ for(i=0;i<m1;i++) for(j=0;j<n1;j++) { [...]
Addition of Diagonal Elements in Matrix
#include<stdio.h> #include<conio.h> void main() { int i,j,a[10][10],sum,m,n; /* m - Number of rows n - Number of Columns */ printf(“\nEnter the number of Rows : “); scanf (“%d”,&m); printf(“\nEnter the number of Columns : “); scanf (“%d”,&n); /* Accept the Elements in m x n Matrix */ for(i=0;i<m;i++ ) for(j=0;j<n;j++) { printf(“Enter the Element a[%d][%d] [...]
Addition of All Elements in Matrix
#include<stdio.h> #include<conio.h> void main() { int i,j,a[10][10],sum,m,n; /* m - Number of rows n - Number of Columns */ printf(“\nEnter the number of Rows : “); scanf (“%d”,&m); printf(“\nEnter the number of Columns : “); scanf (“%d”,&n); /* Accept the Elements in m x n Matrix */ for(i=0;i<m;i++) for(j=0;j<n;j++ ) { printf(“Enter the Element a[%d][%d] [...]
Accessing 2-D Array Elements In C Programming
Accessing Array Elements To Access Every 2-D Array we requires 2 Subscript variables. i - Refers the Row number j - Refers Column Number a[1][0] refers element belonging to first row and zeroth column Accept & Print 2×2 Matrix from user #include<stdio.h> #include<conio.h> void main() { int i,j,a[3][3]; /* i = For Counting Rows j [...]