Hi friends...
I have a problem with some c codes and I think that you will be Capable to point it up for me.
However, I do not want anybody to post the correct and complete code to me .
I want to enter a string of numbers and the program will check whether the entered string forms a multiplicative identity n*n matrix which means all elements are zero except for the diagonal elements
For example, 3*3 multiplicative identity
1 0 0
0 1 0
0 0 1
I think but I am not pretty sure that the problem is from the outer for-loop. But still I cannot figure the error out and here is my code fragment written in C:
======================================================
#include <stdio.h>
#include <string.h>
int main()
{
int size,track=0,i,j ,sum=0;
char string[400];
printf("Enter the size of the matrix: ");
scanf("%d",&size);
gets(string);
printf("Enter the %d by %d matrix (in row-order) ",size,size);
gets(string);
printf("the matrix elements are = %s \n", string);
//notice that the entered string should be Separated by single space only
for(j=0;j<(2*size*size-1);j=(j+2*size-1)) //go row by row
{
for (i=0;i<2*size;i=i+2) //go value by value in a single row
{
if (string[j]!=1 && j==track || string[j]!=0 && j !=track)
sum= sum;
else if ((string[j]==1 && j==track) || (string[j]==0 && j !=track))
sum++;
}
track++;
}
if (sum==(size*size) )
printf("This matrix is a multiplicative identity\n");
else
printf("This matrix is not a multiplicative identity\n");
return 0;
}
=========================================
thanks.
and Remember I do not want to see any complete structure of the solution
the_shark
<< moderator edit: added code tags: [code][/code] >>