GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Nov-2005, 14:01
jack223 jack223 is offline
New Member
 
Join Date: Nov 2005
Posts: 15
jack223 is on a distinguished road

Two-dimensional array....is my answer right?


I don't know if i understood the question correctly or not?
Is my answer right?

here is the question:

Write a function that initializes the components of a two-dimensional array in the following manner: components above the upper-left to lower-right diagonal should be set to 1. Those below the diagonal should get –1 and those on the diagonal should be initialized to 0. Assume the array has width and height equal to arraysize, where arraysize is a global constant. Write a short test program that calls your function and displays the resulting array. For example, a 3x3 array would be initialized to:
0 1 1
-1 0 1
-1 - 1 0

Here is my code:

CPP / C++ / C Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;

const int arraySize = 3; 

int main()
{
	int table [arraySize] [arraySize]= {{1}, {-1, 0}, {-1, -1}}; 	

	for (int rows = 0; rows < arraySize; rows++)
	{
		
		for (int cols = 0; cols < arraySize; cols++ ) 

			cout << setw(3) << table [rows] [cols] << " ";

			cout << endl;
	}

	cout << endl;
	return 0;
}

Here is my Output:


1 0 0
-1 0 0
-1 -1 0
Last edited by admin : 04-Nov-2005 at 18:23. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 04-Nov-2005, 14:42
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,623
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Two-dimentioanl array....is my answer right?


Quote:
Originally Posted by jack223
I don't know if i understood the question correctly or not?
Is my answer right?
First of all, here is the example output from your problem statement:
Code:
0 1 1 -1 0 1 -1 -1 0


Here is the output from your program:
Code:
1 0 0 -1 0 0 -1 -1 0

They don't look the same to me.

Next I have a problem with your interpretation of the program specification. I would read it to mean that you have a single global constant arraysize, and you can make your program work for different arrays by changing the value of the constant.

For your program you would have to rewrite the whole thing if arraysize changed from 3 to, say, 5.

Regards,

Dave
  #3  
Old 04-Nov-2005, 18:16
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: Two-dimentioanl array....is my answer right?


Hey jack223

You've been asked twice to read the guidelines by Paramesh, and the admin has corrected your posts and asked you to use code tags twice. Maybe now is the time to do it?
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer Usage in C++: Beginner to Advanced varunhome CPP / C++ Forum 0 19-Aug-2005 09:25
Dynamic allocation of multi dimensional array pointer C Programming Language 7 13-May-2005 23:50
Array 1 dimensional help please asap lion123 C Programming Language 10 18-Feb-2005 21:53
template comiling problems - need expert debugger! crq CPP / C++ Forum 1 01-Feb-2005 21:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.