473,804 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
Hi..i'm very new to thic C++ programming..in doing my assignment i face some difficulties..f irst
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",&res ults[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 2547
horace1
1,510 Recognized Expert Top Contributor
Hi..i'm very new to thic C++ programming..in doing my assignment i face some difficulties..f irst
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
ayasofya
2 New Member
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
40776
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 style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person filling out the form is switching from page to page...without the overhead of extra hits on the server,...
10
13466
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 related to checkboxes. Thanks!!!
7
6066
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 there any other way to display/undisplay parts of web pages? TIA
5
1185
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 developp this app using Visual C++(6 or .NET). These data are coming right from an electronic device, and I need to display and print result as graphs in a short amount of time (less than 8 hours :o) )
15
12495
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 toggling on again. Furthermore, UAs do not recognize the same values. To make a table row visible, IE wants display:block while FF wants display:table-row. Am I missing something? I am looking for something like display:normal
10
3676
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 key="DEBUGCleanFile" value="true"/> </appSettings>
11
3470
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 other pieces of information information and retrieve it later... like this: *********************** //supossing i have a istream
1
2295
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 combine the "Edit" and "Display" funtions into this page. (It means if user want to edit the customer information, this page would provided editing page to the user; If the user want to display the customer information, this page would providev the...
1
13616
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 <vector> int main() { std::vector< std::vector<int> > v;
4
5239
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 3D coordinate and its 2D label might be right-aligned to the 2D projection of that 3D point. The following Mathematica plot illustrates the functionality I am after: http://math.arizona.edu/~goriely/M322/Mathma-ComplexFunc.jpg I have done...
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.