Click here to Skip to main content
15,916,949 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when i run this program it show me the answer is -584635613 ?

// control proje 3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std ;

int main()
{
	int t[100][100] ;
	int n ;
	int i , j ;
	int s = 0 ;

	cout << "enter the n " << endl ;
	cin >> n ;

	for( i = 0 ; i < n ; i++ )
	{
		for( j = 0 ; j < n ; j++ )
		{
			cin >> t[i][j] ;
		}
	}

	if( t[i][j] != 0 )
	{
		cout << t[i][j];
	}


	return 0;
}
Posted

There's no 'answer'. You create an array of numbers. You then show a value. Here's how it works. You create an array. It's full of random numbers. Then you accept a number, the number of values to accept. Say you entered 5. Now, the first loop starts. i is 0. So, you accept a number. It loops. When i is 5, your loop ends. You have 5 values stored, in index 0, 1, 2, 3 and 4. The value you show, is the value in location 5, which you never set, so it is a random number.

What are you trying to show ?
 
Share this answer
 
Your i and j are both equal to n after the for cycles. Set them to values within your arrays' bounds: [0; n-1]
 
Share this answer
 
Comments
Christian Graus 1-Jul-11 5:31am    
Yes, that's kind of what I said. But, he refers to the 'answer' so there's more going on here. He obviously is expecting something to happen which is not reflected in his code at all, like an attempt to create a sum or something.
Timberbird 1-Jul-11 5:47am    
Absolutely, it just took me too long to write an answer (distracted a bit), so I couldn't see the question has already been answered. Your answer is much more thorough - I'd only add the 'random numbers' in array are actually the content of memory in the moment of allocation
hi yay !
Christian Graus had told you the problems in you program! you should try to remeber that if you going to declare array in you program then you should initialize it or the array1`s element will have random values!
 
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