another question for u guys if instead of 99 is there another way my program can detect that the user is done typing?? what if i do EOF?
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int val, m,x, n, c = 0, d,k, matrix[10][10], transpose[10][10], product[10][10]; //defining variables
printf("Enter the number of columns of matrix ");
scanf("%d",&m);
if(m<=0){ //error checking if user enter negative number or 0 for column
printf("You entered a invalid value.\n");
exit(0);
}
else{
printf("Enter the elements of matrix \n");
for( c = 0 ; c < 10 ; c++) //forst for loop to scan the matrix
{
for( d = 0 ; d < m ; d++ )
{
scanf("%d",&matrix[c][d]);
if (matrix[c][d] == 99) // 'x' is character variable I declared to use as a break
break;
if (matrix[c][d] < 0){ //error checking if any entries in the matrix are negative
printf ("you entered an invalid number\n");
exit(1);}
}
if (matrix[c][d] == 99)
break;
}
}
if (d > 0){ //error checking to make sure the number of entries is correct
printf("The number of entries is not valid\n");
exit(1);
}
printf("\nHere is your matrix:\n");
int i; //declaring i to be count for row
for(i=0;i<c;i++)
{
for(d=0;d<m;d++)
{
printf("%3d ",matrix[i][d]);
}
printf("\n");
}