Hi there, the purpose of this program is to find whether numbers along the diagonal of matrix are same or not.
Code:
#include <stdio.h>
int checkdiag(int matrix[][100], int size)
{
int i,j,status;
for(i=0; i <size; i++)
{
for(j=0; j <size; j++)
{
status = 0;
if(matrix[i][j]==matrix[i+1][j+1])
{
status =1;
}
}
}
return status;
}
int main(void)
{
FILE *ifp;
int **matrix;
int size,i,j,status;
ifp = fopen("matrix.txt","r");
fscanf(ifp,"%d",&size);
matrix = (int**)calloc(size,sizeof(int));
for(i=0; i < size; i++)
{
matrix[i]= (int*)calloc(size,sizeof(int));
}
while(!feof(ifp))
{
for(i=0; i< size; i++)
{
for(j=0; j < size; j++)
{
fscanf(ifp,"%d",&matrix[i][j]);
}
}
}
status = checkdiag(matrix,size);
if(status==1)
{
printf("The Matrix Is %d x %d and and all the numbers on the main diagonal are the same.");
}
else
{
printf("Numbers along diagonal are not the same");
}
fclose(ifp);
free(matrix);
return 0;
}
in file matrix1.txt is this:
3
4 5 6
7 8 9
3 6 7
and the error im getting follows:
lab10.c(42) : warning C4047: 'function' : 'int (*)[100]' differs in levels of in
direction from 'int **'
lab10.c(42) : warning C4024: 'checkdiag' : different types for formal and actual
parameter 1
Please Help me out: Thank You.