Jul 16, 2013 at 3:57pm UTC
This is a question on my study guide and I believe the answer is: 543210
is this correct?
with the following input: 456789
what will print out?
int i,tp; int myary[6];
char khar;
for(i=0; i<6; i++)
{
cin.get(khar);
myary[1] = khar – ‘0’;
}
for(i=1; i<6; i++)
myary[i-1] = myary[i-1] + myary[i];
for(i=0; i<6; i++)
cout<<myary[i];
cout endl;
Jul 16, 2013 at 4:18pm UTC
It would be interesting to hear how you got this result.
Last edited on Jul 16, 2013 at 4:19pm UTC
Jul 16, 2013 at 4:39pm UTC
my array holds 6 values and I know it prints in reverse but I wasn't sure if it was just 54 or I had to let it hold 6 places in my array. I am unsure that is why I am asking for help
Jul 16, 2013 at 4:41pm UTC
I do not see where the array is printed in the reverse order.
Jul 16, 2013 at 4:54pm UTC
there are too many errors in that first of all
Jul 16, 2013 at 6:49pm UTC
well idk it is a question on my study guide
Jul 16, 2013 at 6:55pm UTC
It is strange that your guide contains so many typo.:)
For example in this code snip
for(i=0; i<6; i++)
{
cin.get(khar);
myary[1] = khar – ‘0’;
}
only the element with index 1 (one) is assigned.
And here
cout endl;
you omitted operator <<.
If do not take into account the typo this loop
for(i=1; i<6; i++)
myary[i-1] = myary[i-1] + myary[i];
does the following
myary[0] = myary[0] + myary[1];
myary[1] = myary[1] + myary[2];
myary[2] = myary[2] + myary[3];
myary[3] = myary[3] + myary[4];
myary[4] = myary[4] + myary[5];
So you can calculate yourself what values the array will have.
Last edited on Jul 16, 2013 at 6:59pm UTC
Jul 16, 2013 at 7:08pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
#include <vector>
using std::cout;
using std::cin;
using std::vector;
int main(int argc, char *argv[])
{
vector<int > Container(1);
int Counter = 0;
while (cin>> Container[Counter++])
Container.resize(1);
vector<int > Copy(Container.size() - 1)
for (auto I : Container)
Copy[Copy.size() - I] = Container[i];
for (auto I : Copy)
cout<< Copy [I] <<" " ;
}
edit: accidently put a 1 where an I should be in the first for loop
Last edited on Jul 16, 2013 at 7:30pm UTC
Jul 16, 2013 at 7:16pm UTC
oh really and how is that?
[edit] im being sarcastic my code is fine. im merely humoring you while you try to prove me wrong. i know my code works thought [/edit]
Last edited on Jul 16, 2013 at 7:17pm UTC
Jul 16, 2013 at 7:19pm UTC
@DTSCode
oh really and how is that?
As I said in other thread I am not your professor. So try to understand it yourself or wait until someone experienced will point out the bug.
Last edited on Jul 16, 2013 at 7:19pm UTC
Jul 16, 2013 at 7:21pm UTC
thank god you arent my professor you cant code to save your life. as i said i was being sarcastic because there is no bug
Jul 16, 2013 at 7:27pm UTC
I will not even speak about that code shall not be compiled. There is no any sense to spend time to such genius as you.:)
Jul 16, 2013 at 7:29pm UTC
really because i just compiled it. the only issue (and i typed it on the fly so thats why i made 1 mistake) was i made a 1 where an I should be. it compiled and ran fine
Jul 16, 2013 at 7:34pm UTC
It seems that you are incurable.
Without any compiler I see that variable i was defined nowhere.
Copy[Copy.size() - I] = Container[i ];
Change your brain!
Last edited on Jul 16, 2013 at 7:40pm UTC
Jul 16, 2013 at 7:39pm UTC
you know what vlad? when you learn to code come talk to me. i will just ignore you until then because so far you have been arguing with defenses poorer than a third world country and at times given no defense at, just hoping that i will take your current assertion as fact. i know im right and i dont need to the approval of a lowly forum troll who must take his frustration out on those stupid enough to lower themselves to your level. (i am unfortunately referencing myself). so good day. i really hope you can one day support your arguements