i tried that but the exception is still coming
the output is correct if i use type-iteration
and an exception is generated from the type-recursive
the modified code is
Code:
#include<stdio.h>
int is = 0;
int isdiagzero(int a[][10],int m,int n,int *i,int *j)
{
if(((*i)<m)&&((*j)<n))
{
if(a[*i][*j]!=0)
return 0;
else
{
is = isdiagzero(a,m,n,i++,j++); //is this parameter passing right i++,j++
}
}
return is;
}
int readmatrix(int a[][10],int *m ,int *n)
{
int i,j;
printf("Enter the row and column ");
scanf("%d%d",m,n);
if((*m==0)||(*n==0))
return 0;
else
{
printf("\nEnter the matrix\n");
for(i=0;i<*m;i++)
for(j=0;j<*n;j++)
scanf("%d",&a[i][j]);
}
return 1;
}
void printmatrix(int a[][10],int m ,int n)
{
int i,j;
printf("the matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d ",a[i][j]);
printf("\n");
}
}
int isdiagz(int a[][10],int m ,int n)
{
int i,j;
printf("inside isdiag\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if((i==j)&&(a[i][j]!=0))
return 0;
return 1;
}
int main()
{
int array[10][10];
int m,n;
if(readmatrix(array,&m,&n)==0)
printf("ERROR\n");
else
{
printmatrix(array,m,n);
if(isdiagzero(array,m,n,0,0)==0) //type - recursion
// if(isdiagz(array,m,n)==0) //type - iteration
printf("Diagonal not zero !\n");
else
printf("Diagonal is zero !\n");
}
getch();
return 0;
}
this program reads input as
Enter the row and column 3 3
0 1 1
1 0 1
1 1 0
the matrix
0 1 1
1 0 1
1 1 0
----here it gives exception----
i am not getting it --
i suppose the problem lies in understanding recursion..
please help me...