fix my array error!!

instead of showing the array number designated my output all became N=0 and i declared N=0 because would get the error'without initialization' if didn't do so. I suspect the code in bold is the problem because it run fine without it but became weird after inserting the code.Please tell me how to fix this >.<



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
void main()
{
	char choice;
	int num[4][4]={0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6};
	int row,col,N=0;
	
	

		for(row=0;row<4;row++)
	{

		for(col=0;col<4;col++)
		{
		num[row][col]=N;
			printf("N=%d\n",N);
		}
	}

}
What do you want to do in the first place?
You had set N to 0, never changed it and then assing all array elements to N (which equals to 0).
The long code! My purpose is to check the input of the user. let say he put number 1,2,3,4,5,6 but one of the number at least need to be equal like 1,1,3,4,5,6. This is the solution that i only figured out since i only know how to use stdio.h and a limited set of declaration.... Well if u could fix everything make it run then i will be appreciate for it. The major part still lies within {num[row][col]=N;row=x;col=y;} which i suspected to be wrong since even the short code in my previous post already got problem...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
void main()
{
	
	int num[4][4];
	int row,col,N=0,k=0,n=0;


for(row=0;row<4;row++)
	{

		printf("Enter Row %d: ",row+1);

		for(col=0;col<4;col++)
		{
		scanf("%d",&num[row][col]);

		}
	}

for(row=0;row<4;row=row++)
	{
		for(col=0;col<4;col++)
		{
			num[row][col]=N;
			row=x;
			col=y;
			for(row=0;row<4;row++)
			{
				for(col=0;col<4;col++)
				{
					if(row == x && col == y)
					{
						k++;
					}
					if(N == num[row][col])
					{
						n++;
					}
				}
			}
		}
	}
	if(n>k)
	{
		printf("good\n");
	}
	else
	{
		printf("bad\n");
	}
}
I say it again: You are setting N to zero and never changing it. So statement num[row][col]=N; is equal to num[row][col]=0;
but if i don't do so i can't even start the program due to error of 'The variable N is being used without initialized' so any suggestion to solve this problem??
nvm..... i realize my own mistake..... my mindset thought programming equation is the same as mathematic.... x=y is same as y=x but actually different in in programming =.= thx anyway~ solved my problem!!
Topic archived. No new replies allowed.