- #1
RJLiberator
Gold Member
- 1,095
- 63
Homework Statement
The goal is to create two arrays that have the values
a = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
b = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
And then graph them so that a=mb
slope m thus being 2.
I am working on the first part before I graph them.
Homework Equations
The Attempt at a Solution
Code:
{
int a[10];
for(int n=0; n<10; n++)
{
a[n] = 2+2*n;
}
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<" "<<a[6]<<" "<<a[7]<<" "<<a[8]<<" "<<a[9]<<endl;
int b[10];
for(int r=0; r<10; r++)
{
b[r] = r+1;
}
cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]<<" "<<b[4]<<" "<<b[5]<<" "<<b[6]<<" "<<b[7]<<" "<<b[8]<<" "<<b[9]<<endl;
}
My question:
a) Is there anything I can do to make the code shorter?
b) My professor wants the output to be in the form a[10] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 } instead of vertical list. That's why I had to do the cout<<...<<endl. Is there anyway to make this output more easier than simply listing all the a[1]<<a[2]... etc.?
c) If I've done everything correctly here, how do I go from having these 2 arrays to inserting them into a simple xy graph? Any pointers to get me started there? I'm looking through tutorials now.