Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to get the second input in C arrays but it wont taking , I'll put the code bellow !! can anyone find whats wrong with my code?

What I have tried:

C
#include <stdio.h>

int main()
{
    int num[2][2];
    int sum[2][2];
    int i,j,k,l;
    printf("Enter 4 numbers:\n");
    for ( i = 0; i < 2; ++i)
        for ( j = 0; j < 2; ++j)
            scanf("%d", &num[i][j]);

    // passing multi-dimensional array to a function
    
    printf("\n------------type your next matrix-------\n");
    printf("Enter 4 numbers :\n");
    for (k=0;k<2;++k)
    {
    	for (l=0;l<2;++l)
    	{
    		scanf("%d",sum[k][l]);
		}
	}
    
    
    printf("Displaying :\n");
    for (i=0;i<2;++i)
    {
        for(j=0;j<2;++j)
        {
            printf("%d\t",num[i][j]);
        }
    
        printf("\n");
    }
   
   
   
    return 0;
    
}
Posted
Updated 1-Jun-21 16:59pm
v2

1 solution

Quote:
can anyone find whats wrong with my code?

You input 2 arrays in this code, why don't you do it same way ?
C++
    for ( i = 0; i < 2; ++i)
        for ( j = 0; j < 2; ++j)
            scanf("%d", &num[i][j]);

    // passing multi-dimensional array to a function
...    
    for (k=0;k<2;++k)
    {
    	for (l=0;l<2;++l)
    	{
    		scanf("%d",sum[k][l]);
		}
	}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900