Matrix Addition Using Recursion In C


#include<stdio.h>
#include<conio.h>
void add(int [][2],int [][2],int [][2],int ,int,int);
void dis(int [][2],int);
void main()
{
	int a[2][2],b[2][2],c[2][2],i,j,n=2;
	clrscr();
	printf("\nEnter MAtrix A:");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	printf("\nEnter MAtrix B:");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&b[i][j]);
		}
	}
	add(a,b,c,0,0,n);
	dis(c,n);
	getch();
}
void add(int a[2][2],int b[2][2], int c[2][2],int i,int j,int n)
{
     if(i<n)
     {
	  if(j<n)
	  {
		c[i][j]=a[i][j]+b[i][j];
		j++;
		add(a,b,c,i,j,n);
	  }
	  j=0;
	  i++;
	  add(a,b,c,i,j,n);
     }
}
void dis(int c[2][2],int n)
{
	int i,j;
	printf("\nAddition matrix: \n");
	for(i=0;i<n;i++)
	{
	       for(j=0;j<n;j++)
	       {
		  printf(" %d",c[i][j]);
	       }
	       printf("\n");
	}
}

Login To Download Source Code

Leave a Comment:

Login To Comment

List Of Programs


Goto Examples

Operators

Looping

Number Conversion

Pattern Design

Arrays

Matrix Examples

Sorting Examples

String Function

Change Case

String In C

Maths Functions

User Defined Functions

Recursive Functions

Pointer

Structure

File Concept

Calender Programming