0
If I have an array that is declared and used in a for loop so the user input its value how can I declare new array which his
Elements are divided by the first array (declaring an array using another one)
13 Antworten
+ 2
const int size = 10;
int A[size], B[size];
for (int index = 0; index < size; index++)
{
// read user input
cin >> A[index];
}
if (A[size] == 0) {
// division by zero
}
for (int index = 0; index < size; index++)
{
// your calculation
B[index] = A[index] / A[size - 1];
}
+ 3
Do you mean there is a second array with numbers already in it? Or are you asking users for two numbers, dividing them, and putting them in an array?
Do you have any code to show us so we can understand better?
+ 3
Short answer:
1) declare Array A,B of size 10
2) read 10 values into A
3) iterate through A, devide by A[9], store to same position of B
(special case: devision by 0)
Done.
+ 3
As Daniel Adam said, it would be far better for you to show us your code so we can see what you've actually tried; if you haven't already tried, it's unfair to expect anyone to write it for you from scratch.
+ 3
Manar Ksm
The code you submitted is more like an error correction task than the code you made.😕
+ 2
Can you please provide your current state of the Code. That's easier to adopt or give hints how to solve it. Thx.
+ 1
Sorry, but I can figure out what you're question may be.
+ 1
Manar Ksm - step 2) and 3) are Loops. (You can do this manually but it would be boiler plate code .. and imagine 100 inputs).
0
First I declare an array A of size 10
Then I ask the user to enter the array values using for loop
Now I should divides all the array values by the value of the last element of the array and put the value into new array B
The last step I don't know how to do it :(
0
The third step should be done in the for loop where I asked the user to enter 10 values?!
0
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int A [10];
double B [10];
int newArray;
for (int i = 0; i < 10; i++)
{
cout << "please enter an integer numbers" << endl;
cin >> A[i];
newArray = A[i];
}
for (int j = 0; j < 10; j++)
{
B[j] = {newArray/A[10]};
cout << B[j] << endl;
}
return 0;
}
devisfun thats my code
And I think that Daniel Adam understood that am stuck in declaring B not in need for someone to do my code without even trying for that :)
0
And that's why I need help :(
0
Daniel Adam Thanks so much :-D