Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
3.	Write a program to read integers from a file arrayadd.txt. The first integer on the file would be size of array N. The next N elements would be elements of the array A. The last N elements would be elements of another array B. The program should declare the arrays, input the data, print each array on separate lines, add the corresponding elements of both these arrays  to form array C. Finally, the program should print the elements of the array C.


What I have tried:

reading the question, but couldn't understand. so please help. thank you so much.
Posted
Updated 29-Aug-22 4:52am
Comments
CPallini 29-Aug-22 1:48am    
You don't understand, what?
The requirements look clear.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

If you don't understand the question, you need to discuss that with your tutor.
 
Share this answer
 
See C - File I/O[^].

But if you really do not understand the question then you should talk to your teacher about it.
 
Share this answer
 
The task is not clear.
Assumption: If only one (the first) integer in the file specifies the size N of the array, I would assume a square array of size NxN. But then not only N elements should follow, but NxN values. If the array B has no own size but follows directly without size specification it would be exactly the same for B. If this is clarified, you can allocate the necessary space, read in the values and perform the arithmetic operation. How to add matrices is written in the math book or you can find it with the search engine.
 
Share this answer
 
Comments
Richard MacCutchan 29-Aug-22 10:59am    
Theer is no mention of matrix arithmetic in the question. It suggests two 1D arrays of length N. Each contains N integers, and the task is to create array C containing the sums of the matching elements of A and B:
int A[] = { 1, 2, 3 };
int B[] = { 2, 4, 6 };
int C[] = { 3, 6, 9 };

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