Here is my source code of inputting and print the matrix:

#include<stdio.h>
int main(void)
{
    unsigned int m,n;
    int a[10][10];
    int i,j;
    int temp;
    printf("Plz enter the number of rows of Matrix:\n");
    scanf("%d",&m);
    printf("Plz enter the number of columns of Matrix:\n");
    scanf("%d",&n);
    
    printf("Enter elements for the Matrix:\n");
    for(i=0; i<m ;i++)
    for(j=0; j<n; j++)
    {
             printf("Element[%d][%d] is: ",i,j);
             scanf("%d",&temp);
             a[i][j]=temp;
             }
    printf("The Matrix is:\n");
    for(i=0; i<m ;i++)
   {
       for(j=0; j<n ; j++)
            printf("%d ", a[i][j]);
       printf("\n");
   }
    getch();
    return 0;

I don't know the difference between the direct entering value for element of matrix:

printf("Enter elements for the Matrix:\n");
    for(i=0; i<m ;i++)
    for(j=0; j<n; j++)
    {
             printf("Element[%d][%d] is: ",i,j);
             scanf("%d",&a[i][j]);
           }

and through the temporary like code before:

printf("Enter elements for the Matrix:\n");
    for(i=0; i<m ;i++)
    for(j=0; j<n; j++)
    {
             printf("Element[%d][%d] is: ",i,j);
             scanf("%d",&temp);
             a[i][j]=temp;
             }

Because when running both of them runs very well without any bugs.

Recommended Answers

All 7 Replies

None at all springs to mind.
At least none that matters.

I don't understand your idea?

I don't understand your idea?

You asked:

I don't know the difference between the direct entering value for element of matrix and through the temporary like code before.

Salem answered:

None at all springs to mind.
At least none that matters.

Which means that:
He doesn't see an important difference between using a temporary variable, or directly writing to the matrix.

No no I don't understand what he means or I don't understand his answer. :(.
Or he means that both two above source code is correct and they are the same?

You'll get the same answers when you run either program.

They're functionally equivalent.

yeah, I know that but why we should use the temporary variable to save the value before passing it to array's element?
Here, I means the advantage or strength when using the temporary variable.
help me understand more clearly! don't be peevish! thanks a lot!

Presumably, using non-temp value is faster.

Think of whats going on.

using temp :

1) Get the value from the user.
2) Copy that value to the address of temp.
3) Search for the value that resides in temp address
4) Copy that value and put it in the address of the array

without using temp :
1) Get value from user.
2) Copy value and place it inside of array address.

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.