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,,,

Recommended Answers

All 2 Replies

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.

@ 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

commented: right :) +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.