473,465 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading from user into array

1 New Member
I am lost on my homework and need help .... here is what I am trying to do and the code I am working on is below it
Write a program for Matrix addition for two 3 by 3 matrices. -Take the input from the user. -Print both the input matrices and the output matrix.

#include<stdio.h>
main()
{
int aArray[3][3];
int bArray[3][3];
int cArray[3][3];
int a,b,c,d,e,f;

for(c = 0; c==2 ; c++)
{
for(d = 0; d==2 ;d++)
{
printf("enter values for Array 1: /n");
scanf("%d", aArray[c][d]);
}
}

for(e = 0; e==2;e++)
{
for(f = 0; f==2; f++)
{
printf("enter values for Array 2");
scanf("%d", bArray[e][f]);
}
}

for(a = 0; a==2;a++)
{
for(b = 0; b==2;b++)
{
cArray[a][b] = aArray[a][b] + bArray[a][b];
}
}

printf("%d\n", cArray);
}
Oct 16 '06 #1
2 1934
Banfa
9,065 Recognized Expert Moderator Expert
int a,b,c,d,e,f;

You don't need all these variables, 2 will do the job, you can reuse them

for(c = 0; c==2 ; c++)

All your loops are like this, they don't work. This basically says, set c to 0, if c is equal to 2 continue executing the loop, at the end of each iteration increment c. As you can see the loop will never execute because c != 2 on the first attempt to run the loop. This would normally be written as

for(c = 0; c<3 ; c++)

Reading as set c to 0, if c is less than 3 continue executing the loop, at the end of each iteration increment c.

3 is a mgic number in your code, you should #define it.

It would be better if you indicated which element the input request was for by outputing c and d.

printf("%d\n", cArray);

This wont work, you will get the value of the pointer pointing at cArray. If you want to output the matrix then you will need to use 2 loops to get the value of every element and print it in the same way you use 2 loops to input every element and to do the addition.
Oct 16 '06 #2
dtimes6
73 New Member
#include<stdio.h>
main()
{
int N = 3;
int aArray[N][N];
int bArray[N][N];
int cArray[N][N];
int a,b;

for(a = 0; a!=N ; a++)
{
for(b = 0; b!=N ;b++)
{
printf("enter values for Array 1: /n");
scanf("%d", aArray[a][b]);
}
}

for(a = 0; a!=N;a++)
{
for(b = 0; b!=N; b++)
{
printf("enter values for Array 2");
scanf("%d", bArray[a][b]);
}
}

for(a = 0; a!=N;a++)
{
for(b = 0; b!=N;b++)
{
cArray[a][b] = aArray[a][b] + bArray[a][b];
}
}

printf("%d\n", cArray);
}
Oct 16 '06 #3

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

Similar topics

1
by: Roger Godefroy | last post by:
Hi there... I want to read fieldvalues from out of a dynamicaly created table (php). But this has to be done by JavaScript. Every row of the table has a select-box, inputbox and a order-button....
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
1
by: Mr. B | last post by:
VB.net 2003 c/w Framework 1.1 and MS Access db We have a commercial program that does our Acounting and Time Sheets (Timberline). At least once a day our Accounting department runs a Script...
4
by: Jason | last post by:
Could anyone spare some time and try to help me out. I've got a .txt data file with a name, pin, balance seperated by commas. I am opening the file and using Split to split it between the ,'s I...
2
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads...
21
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.