0

hi

Am trying to write a C-code that multiply two matrices
but i want the elemnets of every matrix is random number using time function

main()
{
  srand ( time(NULL) );

  int m1[10][10];
  m1[10][10] = rand() % 10;
  scanf("%d%d",&r1,&c1);
  scanf("%d%d",&r2,&c2);
  if(r2==c1)
  {      


        .
        .
        .
        .
    }

this is the first matrix only
when i output tihs matrix

    printf("First Matrix is :n");
    for(i=0;i<r1;i++)
    {
        for(j=0;j<c1;j++)
            printf("%dt",m1[i][j]);
        printf("n");
    }

i get rapish numbers in some elements
like that

  5777072       5767844
  3             1971339732

and i don't know why that
any one know ??
thx,,,

Edited by MicrosoftMahmou: Edit in output

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by zeroliken
0

m1[10][10] = rand() % 10;

that is doing nothing but populating a single cell, which is NOT in the matrix, with a single random number. There is no such cell in that matrix.

if(r2==c1)

Huh? What difference does it make if r2 is the same value as c1? r2 is a row number in the matrix and c2 is a column number. The two values are unrelated.

Edited by Ancient Dragon: a

1

@ line 6
your assigning a value to the null terminator of the matrix

i want the elemnets of every matrix is random number using time function

instead you should make a nested loop that traverses it's indexes and inside that loop it assigns a random value for the current index

Votes + Comments
right :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.