473,382 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

To store and display elements of 2D-array..

Hi..i'm very new to thic C++ programming..in doing my assignment i face some difficulties..first
1) i use 2 dimension of array e.g," 1 columns and 5 numbers under each column"...and i ask the user the fill the numbers
2)Then, i want display back all the numbers that have been stored but it just display the last number in the column..i don't have any idea to make it display all the inputs..

Here, the programme that i've written so far...if anybody can help me and i do really appreciate that...

__________________________________________________ ______________



#include <stdio.h>
#define COL 1
#define NUM 6




int main (void)
{


int results[COL][NUM];


int col = 0, num= 0, temp = 0;

do {

printf("\nFor column %d ",col +1);
printf("\t");
while(num < (NUM - 1)) {

printf("\n\t ",&results[col][num]);
scanf("%d",&results[col][num]);
++num;

}
num = 0;
++col;
} while (col < COL);

col=0;
++num;



do {
do {
temp = results[col][num];
++num;
}while(num < (NUM - 1));
results[col][NUM-1]= temp;
temp = 0;
num = 0;
++col;
}while (col < COL);



col = 0;
++num;

printf("the matrice is...");
do {
printf("\n %d\n\t", results[col][NUM-1]);
++col;
++num;
}while (col < COL);
getch();
return (0);
}
Nov 25 '06 #1
2 2526
horace1
1,510 Expert 1GB
Hi..i'm very new to thic C++ programming..in doing my assignment i face some difficulties..first
1) i use 2 dimension of array e.g," 1 columns and 5 numbers under each column"...and i ask the user the fill the numbers
2)Then, i want display back all the numbers that have been stored but it just display the last number in the column..i don't have any idea to make it display all the inputs..

Here, the programme that i've written so far...if anybody can help me and i do really appreciate that...
}
when you print the matrix you only print the last element - you need another loop, e.g.
Expand|Select|Wrap|Line Numbers
  1. printf("the matrice is...");
  2. do {
  3.     for(num=0; num<NUM-1; num++)
  4.        printf("\n %d\n\t", results[col][num]);
  5. ++col;
  6. }while (col < COL);
  7.  
for simple loops it is usually easier to use a for() loop to do the same thing as a while(), e.g.
Expand|Select|Wrap|Line Numbers
  1. printf("the matrice is...");
  2. for(col =0; col<COL; col++)
  3.     for(num=0;num<NUM-1;num++)
  4.        printf("\n %d\n\t", results[col][num]);
  5.  
you could change your input to use a for()
why do you have 6 elements in the array and only use 5?
Nov 25 '06 #2
oh thanx a lot...hurm i think i juz make it too complicated, act i can juz simply define NUM 5 and num<5 as it starts from num=0...
anyway i can now display all the elements but how to make it really looks like the arranggement of a matrix...

for e.g if i have 2 columns

first column
1
2

2nd column

3
4

but how display the whole matrix like this?
1 3
2 4
Nov 25 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
5
by: Gill | last post by:
Hi There, Does anyone can give me advices to choose a graphical library/control/ocx/other to developp an application displaying 2d lines from large data set (around 30 000 points). I have to...
15
by: Markus Ernst | last post by:
Hi When toggling an element on and off by setting its display property via DOM access, display:none is valid for all kinds of elements, but I can't find anything about a generic value for...
10
by: Brett Romero | last post by:
I'd like to store something such as the following the my app.config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DEBUG" value="true"/> <add...
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
1
by: Benny Ng | last post by:
Dear All, Now I met one problem in the development of my one application. I have one ASP.NET page. It's for disply the information of customer. But now I have one new requirement. It's to...
1
by: tinie | last post by:
I encounter problems in inserting elements in a 2d vector. For example I want to insert 99 in v, how would I do it? What I have is this code: #include <iostream> #include <iomanip> #include...
4
by: Jon Harrop | last post by:
I am writing a 3D graphing component built upon WPF and would like to have 2D vector graphics (e.g. typeset mathematics) as labels laid out from 3D coordinates. For example, a tick on an axis has a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.