Array in C programming21 min read

  • An array in C can be defined as memory location under a single variable name i.e. we will define only one variable which is able to hold a finite consecutive memory location for storing all the elements and then we will refer to all the elements by means of a subscript or index variable one by one or in a random manner.
  • There is one major restriction in using an array is that a finite number of elements of an array must be of the same type and hence they are called homogenous data types.
  • It is a static data type as the programmer need to specify the size and one can not alter this value during the execution of the program.
  • When an array in a ‘C’ program is declared, the compiler allocates a base address and amount of storage to contain all the elements of an array in a contiguous memory location. The base address is the location of the 1st element (index () of the array. The compiler also defines the array name as a constant pointer to the 1st element.

Some common examples of Array: An array for storing a set of marks scored by students in a class, a bit of matrix table for a computer screen, for solving matrix problems.

Types of array in C

  1. One-Dimensional Array
  2. Two-Dimensional Array
  3. Jagged/Ragged Array

One-Dimensional Array

When array values are referred to by a single subscript variable then it is known as a One-Dimensional array. It can be defined as an array with N elements where each element is stored in consecutive memory locations. To store N elements together all the N memory locations have the same array name and are contiguous to each other

Memory Storage Representation of One-Dimensional Array:

array in C

Declaration of single-dimension array

  • Like any other variable arrays must be declared before they are used and one must be spectra it within square brackets ([ ]).
  • Size can not be altered during the execution of a program and hence name static memory allocation: Arrays should be declared as any basic data type with subscripted numbers given within square brackets.
  • The size which should be a positive integer constant indicates the maximum or fixed number of elements that an array can hold Naming an array follows the same rule as that of a variable Thus a declaration must give the following information,
  • The data type of an array
  • Name of Array
  • Size or Length of the array

Syntax: data type array_name(Size);

Ex.

1) int LA[10];

Indicates that –

  • LA is the name of the array
  • Its data type is an integer
  • The index set can hold a maximum of 10 values i.e. domain start with LA[0] to LA

2) float salary[50]; /* Can store salary of 50 employees */

3) unsigned int age[15]; / * Can store age of 15 persons */

4) char name[20]; / * Can hold only one name */

RULES:

  1. All the elements in a given array must be of the same type.
  2. Arrays are initialized with constant only.
  3. No two arrays can have the same name in the program.

Initialization of array

Like normal variable array can be initialized during declaration,

Syntax : static (data type) array_name[size] ={list of values separated by comma};

Ex:

  1. static int number [3] = {0,0,0);
  2. static float salary [3] = { 2000.00, 3000.00, 3456.00 };
  3. char name [7] = { ‘P’,’A’,’S’,’C’,’A’,’L’,’\0′}; OR char name [7] = ” PASCAL”;
  4. float sum [5] = {6.5, 7.6 ,7.9};
  5. Here the last 2 elements will be set to zero automatically.
  6. Array counting number of elements: The declaration of the maximum number of cells in the array can be omitted if the initialization values are present. The compiler automatically counts the number of elements in the array.

Ex. int marks [ ] = {10, 20, 30, 40 ,50};

In the above case, it is 5. The compiler takes the array to be size 5.

Writing/accepting the elements into an array

One can write or store elements into an array by the initialization method as described above. The second method is to accept the values for the array at run time using the subscript method. Generally, a set of values are accepted through for loop.

Assume one would like to accept 5 values then one of the techniques is,

  • scanf(“%d”,&a[0]);
  • scanf(“%d”,&a[1]);
  • scanf(“%d”,&a[2]);
  • scanf(“%d”,&a[3]);
  • scanf(“%d”,&a[4]);

But above method is cumbersome if one would like to accept 50 values. A better solution is,

for( i = 0; i < 5; ++i) 
{
  scanf("%d",&aſ i ]); 
}

Reading an element from an array

Once the value is written or stored in an array, it can be processed sequentially or ng while used sequentially for various operations depending upon need by reading or accessing from an array,

Syntax to read the element from the array is

Array_Name[Index_poistion) or Index_Positionſ Array_Name]

Ex: 1) To Read Access the 5th position value from the array and store them into the variable K = a[+]; /* Remember that array count starts from 0 rather than usually 1 */

2) To Read Access 2nd, 3rd, and 8th position values and sum them

Sum a[l] + a[2] + a[7]; Sum = 1[a] + 2[a] + 7[a];

3) To Read Access all the elements of the array say 10 and print them

for (i = 0; i<10; ++i) 
{
  printf ("od",ali ]);    /* or printf("Cod". i[a]); */
}

With Array

Program to find the sum of any five numbers using an array

#include <stdio.h>
#include <conio.h>
#define N 5 

void main(void) 

{ 
  
  int a[ N ], i, sum=0; 
  
  clrscr();                 
  /* Accepting Writing values into an array */ 
  
  for (i= 0; i< N;i++)
  {
   
    printf(" Enter %d number :-", i+ 1); 
    scanf("%d",&a[i]);   
  
  }
    
  /* Reading/Accessing values from an array*/ 
  
  for (i= 0; i < N; i++) 
  { 
    sum = sum + a[i]; 
  }
  
  printf("Sum=%d",sum); 
  
  getch(); 
  
}

To find the total positive and negative among any five numbers

#include <stdio.h>
#include <conio.h>
#define N 5

void main(void) 

{
   
   int a[ N ], i, pos, neg; 
   clrscr(); 
   
   pos = neg = 0;            
  
  /* Accepting/Writing values into an array */
   
   for (i= 0; i< N; i++) 
   
   {
     
     printf(" Enter %d number :-", i + 1);
     scanf("%d",&a[i]); 
     
   }               
  
  /* Reading/Accessing values from an array*/ 
   
   for ( i= 0; i < N; i++ )
     
   { 
     
     if ( a[i]>0 )
     
       pos = pos + 1;         /* Increment positive counter */
       
     else 
       
       neg = neg + 1;          /* Increment negative counter */
     
   }

   printf("\n Total Positive = %d", pos);
   printf("\n Total Negative = %d", neg);
       
   getch();
   
}

Observe that, we require very few variable declarations and few statements to carry out the same set of operations on variables using array concepts.

Change the value of N as per your requirement, as we are using Static Memory Management it is not possible to change the value of memory allocation for array variable during execution time. Later on, while using the pointer we will resolve this problem.

Important Note

Transforming values/contents of one array to another

One can not assign the values of one array into another in ‘C’ Language simply by assignment statement using single instruction like we use to do with basic data type i.c. the following coding is wrong,

void main() 
{
  int a[5] = {5,6,7,1,2}; 
  int b[5];
  b = a;
         /* ERROR */
}

The solution for the above problem is,

  1. Use memcpy () function, which copies a block of n bytes from source to destination and one must include and will be discussed in the chapter pointer.
  2. Copy individual element from the first array to another using some looping statement like given below,

Demo of preserving array list of numbers

#include <stdio.h>
#include <conio.h>

void main(void) 

{

  int a[5]={5,3,7,1,2}; 
  int b[5]; 
  int i; 
  clrscr(); 
  
  for(i=0;i<5;Hi)
  
  { 
    
    b[i] = a[i];          /* Copying elements */
   
  } 
   
   for(i=0;i<5;+i) 
     
   {        
     
     printf("%d -> %d %d\n",i+1,a[i],b[i]); 
    
   }
   
   getch(); 
  
}

If two arrays are the same (Having the same data type & size) then one can not compare them like ordinary variables and must compare them element by element.

Important Note

SEARCHING

  • Finding the location of an element with a given key value or finding the location of all elements that satisfy one or more conditions is called searching.
  • It is one of the important operations and will let us know the presence and absence of a particular element.
  • Operation is said to be successful if a key value is found, otherwise, it is referred to as unsuccessful.
  • An internal search means those searches where the list is kept in a main memory-like array.

There are two important native or basic methods of searching

1) SEQUENTIAL / LINEAR SEARCH

  • In linear search, the search begins at one end of the list and scans down the element of the list until the desired key is found or the other end is reached, which indicates the item is not present in the list.
  • Here, the list may or may not be in a particular order.
  • Linear search is a type of brute force method since the logic of the algorithm forces us to examine each and every element of the array for a specified key to be searched.

Program to search item/clement says k in an array and print the position where the item is found

#include <stdio.h>
#include <conio.h>
#define SIZE 50 

void main(void)

{
  
  int a[ SIZE ]; 
  int i, n,p,k; 
  int flag=0; 
  
  clrscr(); 
  
  printf(" Enter how many elements to be enter (1 %d) :- "SIZE); 
  scanf("%d",&n);    
  
  /* Validating Memory Allocation */
  
  if(n > SIZE) 
  
  {
    
    printf(" Memory is not enough allocated, Press a Key"); 
    
    getch();
    return; 
    
  } 
  
  /* Accepting/Writing values into an array */
   
  for (i=0; i<n; ++i) 
    
  {
    
    printf(" Enter %d element ",i+1);
    scanf("%d",&a[i]);
    
  } 
  
    printf("\n Enter the item to be search :- "); 
    scanf("%d",&k);           
  
    /* Searching Procedure Begin */ 
    
    for(i=0;i<n;+i) 
    
    {
      
      if(a[i] == k) 
      
      {
      
        p = i; 
        flag = 1;      /* found at position i */ 
        break;
        
      } 
      
    }                         
    
    /* Search Result */ 
    
    if(flag == 0)
      
      printf("\n Item %d is not found in the list ",k);
  
    else
      
      printf("\n Item %d is found at position %d",k,p+1); 
      
    getch();
  
}

Program to a checklist of elements is in sorted order (Ascending) or not

#include <stdio.h>
#include <conio.h>
#define SIZE 10 

void main(void)

{
    
  int a[SIZE]; 
  int i,n;
  
  clrscr(); 
                    
  printf(" Enter how many elements to be enter (1 - %d) :-",SIZE); 
  scanf("%d",&n);      
  
  /* Validating Memory Allocation */ 
  
  if(n > SIZE) 
  
  {
    
    printf(" Memory is not enough allocated, Press a Key");
    getch();
    return; 
    
  }                   
  
  /* Accepting/Writing values into an array */ 
  
  printf("\n\n Enter the elements in sorted order \n"); 
  
  for (i=0; i<n ; i++) 
  
  {
    
    printf(" Enter %d element ",i+1); 
    scanf("%d",&a[i]);
    
  }
                    
  /* Checking entered element is in ascending order or not */
  
    for (i=0; i<n-1; i++) 

    {

      if (a[i] > a[i+1]) 
  
      { 
  
        printf(" Element %d is not in order", a[i+1]); 
        getch();
        return; 
    
      }
  
    } 
    
    printf("\n All the elements in the list are in the order "); 
    
 getch()
  
}  

2) BINARY SEARCH or SEARCHING AN ORDERED LIST

  • This method requires that the list should be in a sorted order either ascending or descending order.
  • Here unlike the sequential method, it is not necessary to compare each and every element of the list.
  • As the list is in sorted order, it minimizes the number of comparisons to locate or search an item and thus, reduces search time.

It is also called binary chop as it eliminates half the elements of the list at each iteration. A procedure to search an item is given below,

Repeatedly,

“Examine the middle value of available sorted list and on the basis of Comparison, eliminate (Ignore) the half of the remaining set”

Until

“Element is found or it is observed that element is not found”

Programs to search item/element say k in a sorted array and print the position where the item is found

#include 
include define SIZE 50 

void main(void)

{

  int a[SIZE]; 
  int i, n, p, k, b, e, m; 
  clrscr(); 
  
  printf(" Enter how many elements to be enter (1 - %d) :- ",SIZE); 
  scanf("%d",&n);            
  
  /* Validating Memory Allocation */ 
  
  if(n>SIZE) {
  printf(" Memory is not enough allocated, Press a Key"); 
  
  getch(); 
  
  return;  
  
}
  /* Accepting/Writing values into an array */ 
  
  printf("\n\n Enter the elements in sorted order \n");
  
  for (i=0; i<n; i++) 
    
  {
    
    printf(" Enter %d element ", i+1); 
    scanf("%d",&a[i]);
    
  }
  
  printf("\n Enter the item to be search :- "); 
  scanf("%d",&k); 
  b = 0;
  e = n-1;
  m = (b+e)/2;
  
  /* Searching Procedure Begin */
  
  while (b < e && a[m] != k) 
  
  { 
    
    if(a[m] < k)
      
      b = m + 1;
    
    else
      
      e = m - 1;
    
    m = (b+e)/2;
    
  }
  
  / * Search Result */
    
  if (a[m] ! = k)
    
    printf("\n Item %d is not found in the list", k );
  
  else
    
    printf("\n Item %d is found at position %d", k, m + 1 );
  
  getch ()
    }

SORTING

Operation of arranging unsorted list into some order say increasing or decreasing either on numerical or alphabetical or other data type value is known as sorting.

  • Find the meaning of a particular word in the dictionary which consists of thousands of pages and where words are not arranged in a particular order, then obviously, it will require a lot of time to locate the word.
  • But in the case of sorting, one requires very little time.
  • For example, searching a person’s telephone number using the name in a telephone directory is very easy because of the arrangement of names in sorted order. Thus sorting is considered one of the important concepts.

1) Bubble sort / Bubble exchange sort

  • In bubble sort scanning of the list is performed from top to bottom.
  • Whenever the pair of the adjacent keys are found to be out of order then those elements are swapped or exchanged or interchanged.
  • The basic principle of this method is to compare and exchange pairs of adjacent items until elements are not sorted.

If there are N elements then in general N-1 pass will be required to sort the list. After sorting, the values are arranged as follows,

a[1] a[2] > a[3] > -> a[N] for decreasing order.

  • In the first iteration, we get the largest element at the bottom i.e. at the proper place if it is in ascending order.
  • In the second iteration, the element will be placed at the second last position after comparing all elements.
  • And so on, after (n-1) interaction the nth value will be placed in its proper position and thus, the elements are placed in sorted order.
  • Thus in the case of ascending sorting, one can say that after passing, the smallest element can be placed anywhere in the list but not at the end since it will be occupied by the largest element of the list.
  • Thus, the basic principle of this method is to compare and exchange pairs of an adjacent item until elements are not sorted.

A program to sort the list of N numbers in ascending order using bubble sort

#include <stdio.h>
#include <conio.h>
#define SIZE 50 

void main(void) 

{

  int a[ SIZE ]; 
  int i, j, t, n; 
  
  clrscr(); 
  
  printf(" Enter how many elements to be enter (1 - %d) :- ",SIZE); 
  scanf("%d",&n);              /* Validating Memory Allocation */ 
  
  if(n > SIZE) {
  
  printf(" Memory is not enough allocated, Press a Key"); 
  getch();
  return; 
  
  }                            
  
  /* Accepting/Writing values into an array */ 
  
  for (i=0; i<n; i++) { 
  
  printf(" Enter %d element ",i+1); 
  scanf("%d",&a[i]);           
    
  /* Sorting Procedure Begins */ 
  
  for( i = 0; i < n; ++i) {
  
    for( j = 0; j < n-i-1; ++j) {
  
      if(a[ j ] > a[j+1])          
        
      /* swapping procedure */ 
      
      t = a[ j ]; 
      a[j] = a[j+1];
      
      a[j+1] = t; 
      
      } 
      
      } 
      
      {

  /* Printing Sorted List */ 
  
  printf(" \n\n After sorting, List contain \n"); 
  
  for (i=0; i<n; ++i)
  printf("%d\t",a[i]); 
  
  } 
  
  getch();
  
}
  • Generating Sample Data You might have observed that while executing a program, entering so many values for the array is a tedious job especially when we are checking for the correctness of your program or when we are running with artificial data rather than live or actual data.
  • The solution for the above problem is the predefined function rand/ which generates a number between 0 to RAND MAX and is defined under the header file. Ex. Generating 20 random numbers between 0-99 and writing them into an array for (i=0; i<20 ; i++) a[i] = rand() % 100

2) Selection sort

  • Suppose there are n elements in memory, the sorting works as follows, firstly, find the smallest elements in the list by comparing 1 st element with all the remaining elements and put swap the smallest element with that of 1st element.
  • Secondly, find the 2nd smallest element in the list and put it in the 2nd position, and so on.
  • The basic idea of this sorting is to; Find the Minimum element and then Swap (FMS) with the correct position of the item.
  • The advantage of selection sort over bubble sort is that it requires less swapping i.e. at most (N-1) swapping in the worst case.

A program to sort the list (List should be generated by random numbers) using selection sort

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

#define SIZE 50 

void main(void) 

{
  
  int a[ SIZE ]; 
  int i, j, t, n, min, loc; 
  
  clrscr(); 
  
  printf(" Enter how many elements to be enter (1 - %d) :- ",SIZE); 
  scanf("%d",&n);           
  
  /* Validating Memory Allocation */ 
   
  if(n> SIZE) {
  
  printf(" Memory is not enough allocated, Press a Key"); 
  getch();
  return; 
  
  } 
  
  randomize(); 
  
  /* Generating random numbers between 0-99 and writing them into an array */ 
  
  for (i = 0; i<n; i++) 
  
  {
    
    a[ i ] = rand() % 100 ; 
  
  }                        
  
  /* Printing Random Generated Numbers list */ 
  
  printf(" \n\n Random Generated List contain \n"); 
  
  for (i = 0; i<n; i++) 
  
  {
  
    printf(" %d \t",a[ i ]);
  
  }
  
  /* Sorting Procedure Begins */ 
  
  for( i = 0; i < n; ++i) 
  
  {
  
    min = a[ i]; 
    loc = i; 
  
    for( j = i+1; j<n; ++i) 
    
    {
  
      if(a[j] < min) 
      
      {
      
        min = a[ j ];
        loc = j; 
   
      } 
  
    } 
  
    if(a[loc] <a[i]) 
  
    {
  
      /* Swapping Procedure */ 
  
      t = a[i]; 
      a [ i ] = a[loc);
      a [loc] = t; 
  
    } 
  
  } 
  
  /* Printing Sorted List */ 
  
  printf(" \n\n After sorting, List contain \n"); 
  
  for (i = 0; i<n; i++) 
              
  {
    
    printf(" %d \t",a[ i ]); 
  
  } 
  
  getch();
  
}

3) MERGING

  • Suppose an Array A and B are the sorted lists with M and N elements respectively.
  • The operation that combines the elements of array A and B into a single sorted array list C with M+N element is called merging.
  • It is the process of combining the elements of N arrays to form a new array. When it merges 2-array it is called a two-way merge
  • Ex. : Assume Array LA and Array LB contain following data set,
    • LA = {10, 20, 25} ; LB = {12, 18, 20, 27, 30} ; LC = { }
    • NA = 3 (Number of elements in array LA)
    • NB = 5 (Number of elements in array LB)
  • Let, PA and PB are the two variables that point to the first element of array LA and LB respectively. The smaller LA [PA) and LB [PB] will be put into the 1s” position of array LC.
  • The pointer position of the array either PA or PB will be incremented along with the pointer position of array PC.
  • In our example 10 from array LA will be put into array LC and its pointer will be incremented i.e. PA = PA + 1.

LA {10, 20, 25}; LB = {12, 18, 20, 27, 30}; LC {10}

The entire procedure of merging is given below,

PAPBPCLA[PA]LB[PB]CheckLC[PC]Increment
111101210 < 1210PA
2122012 20 < 12 12PB
2232018 20 < 18 18PB
2342020 20 < 20 20PB
2452027 20 < 27 20PA
3462527 25 < 27 25PA
447

At some point, either of the array elements will be exhausted.

Program to Merge Two Sorted List

include <stdio.h>
#include <conio.h>
#define M 10 
#define N 10 

void main(void)

{

  int a[M], b[N], [M+N); 
  int i, j, t, m, n; 
  int pa, pb, pc; 
  
  clrscr(); 
  
  printf(" Enter how many elements to be enter in the 1st list (1 - %d) :-",M); 
  scanf("%d",&m); 
  
  printf(" Enter how many elements to be enter in the 2st list (1 - %d) :-",N); 
  
  scanf("%d",&n);               /* Validating Memory Allocation / 
  
  if(m > M || n > N) { 
  
  printf(" Memory is not enough allocated, Press a Key"); 
  getch(); 
  return; 
  
  } 
  
  /* Accepting Sorted values into a First array */
  
  for (i=0; i<m ; i++) {
  
  printf(" Enter %d element in array A :-",i+1);
  scanf("%d",&a[i]); 
  
  }

  /* Accepting Sorted values into a Second array */ 
  
  for (i=0; i<n; i++) {
  
  printf(" Enter %d element in array B :-",i+1);
  
  scanf("%d",&b[i]); }         
                   
  /* Merging Procedure Begin */ 
                   
  pa = pb = pc = 0; 
  
  while(pa <m && pb <n) {
  
  if(a[pa] > b[pb]) {
  
  c[pc] = b[pb]; =
  Hpb;
  
  }
  
  else {
  c[pc] = a[pa]; = pa;
  
  }
  
  +pc; } {
  
  /* Copy Remaining Elements from Array A if any */ 
  
  for (i= pa; i<m ; i++) {
  c[pc] = a[i];
  pc; 
  } 
  
  /* Copy Remaining Elements from Array B if any */ 
  
  for (i= pb; i<n; i++) {
  
  c[pc] = b[i];
  
  ++pc; 
  
  }
  
  /* Printing Merge List (After Combining Two Sorted List) */ 
  
  printf("\n\n After Merging the list C contain :- \n"); 
  
  for (i=0; i<m+n; i++) { 
    printf("%d\t".c[i]); 
  } 
  
  getch();
  
}

Multidimensional array

  • An array whose elements are referred to by more than one subscript variable or index is called a multidimensional array.
  • When array values are referred to by a two subscript variable then it is known as a two-dimensional array.
  • Multidimensional arrays are declared in the same manner as a one-dimensional array, except that additional separate pairs of square brackets are required for each subscript.
  • Thus, a two-dimensional array will require two pairs of square brackets.
Syntax: datatype Array Name[Row Size][Column Size];

Where Size should be an integer constant and indicates the maximum number of elements that one can hold in the array. If the size of the row and column are the same then logically its shape is considered square otherwise it forms a rectangular shape/Total number of elements in two-dimensional is calculated by the following formula,

Total-elements = Row Size * Column Size

Initializing Two-dimensional Arrays

Like one-dimension, a two-dimensional array can be initialized while declaring,

Program to find the sum of two matrices having sizes M*N and P*Q

#include <stdio.h>
#include <conio.h> 
#define AB= 35  
#define C 8 [151-61 [1+2 5+6

void main(void) 

{

  int a[R][C], b[R][C],d[R][C];
  int i, j, m, n, p, q; 
  clrscr(); 
  
  printf(" Enter size of matrix A (1-%d) to (1-%d) :-",R,C); 
  scanf("%d %d",&m,&n); 
  
  printf(" Enter size of matrix B (1-%d) to (1-%d) :-",R,C); 
  
  scanf("%d %d",&p,&q);          
  
  /* Validating Memory Allocation */ 
  
  if(m > R || n > C || p > R || 9 > C) 
  
  {
   
    printf(" Memory is not enough allocated, Press a Key"); 
  
    getch();
  
    return; 
  
  }
  
  
  /* Validating, Addition is possible or not */
  
  if(m !=p || n != q) {
  
  printf(" Matrix Addition is not possible, Press a Key"); 
  getch();
  return; 
  
  } 
  
  /* Accepting/Writing values into an array A */ 
  
  printf(" Accept elements in Matrix A : \n"); 
  
  for (i=0; i<m ; i++) {
    for( j = 0; j<n; ++i) {
    scanf("%d",&a[i][j]); 
    } 
   } 
   
   /* Accepting/Writing values into an array B */ 
   
   printf(" Accept elements in Matrix B : \n"); 
   
   for (i 0; i<p ; i++) {

     for( j = 0; j <q; ++i) {
     scanf("%d",&b[i][j]); 
     } 
     
    }
    
    /* Perform Addition of Matrix A and B and store result in C / 
    
    for ( i = 0; i Printing Resultant Matrix */ 
  
    printf("\n\n Result Matrix \n"); 
  
    for (i = 0; i<m ; i++) {
    
      for( j = 0; j <q; ++i) {
        
        printf("%d",d[i][j]); 
      }
        printf("\n"); 
    }
  
    getch(); 
} 

1 2 
3x2

Program to find the product or multiplication of two matrices having sizes MN and PQ

#include B=
#define R 8 +1x3
include
[2x1+1x2 2x2 
#define C 8 d

void main(void)
 

{
  int a[R][C], b[R][C],d[R][C]; 
  int i, j, k, m, n, p, q;
  
  clrscr(); 
  
  printf(" Enter size of matrix A (1-%d) to (1-%d) :- ",R,C); 
  scanf("%d %d",&m,&n); printf(" Enter size of matrix B (1-%d) to (1-%d) :-",R,C); 
  
  scanf("%d %d",&p,&q); 
  
  /* Validating Memory Allocation */ 
  
  if(m > R || n > C || p > R || q > C) {

  printf("Memory is not enough allocated, Press a Key"); 
  getch(); 
  return;
  
  } 
  
  /* Validating, Multiplication is Possible or Not */ 
  
  if(n !=p) /* Matrix Multiplication not Possible */
   printf(" Matrix Multiplication is not possible, Press a Key"); 
   getch();
   return; }
}

Share:

Leave a Reply