#### Archived

This topic is now archived and is closed to further replies.

# C/C++ Brainbuster.

This topic is 6561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well, I just went on an interview where I was almost suckered... Here''s a bit of a brainbuster, what will the output be?: (I guess we''re about to find out who''s awake) int main(int argc, char *argv[]){ int x = 0; char a[26] = {''a'', ''b'', ''c'', ''d'', ''e'', ''f'', ''g'', ''h'', ''i'', ''j'', ''k'', ''l'', ''m'', ''n'', ''o'', ''p'', ''q'', ''r'', ''s'', ''t'', ''u'', ''v'', ''w'', ''x'', ''y'', ''z''}; for(int i=0; i < 8; i++){ x += i; cout << xLink

##### Share on other sites
Sorry, formatting is terrible here... How the hell do I indent something? bleh

##### Share on other sites
It''ll be a number, zero through seven.

##### Share on other sites
if that is supposed to be a complete program, it will give you an error because you have no closing braces for the main and the for statement, otherwise, if everything is ok, it should output: "0 1 3 6 10 15 21 28" and i do not even know c++

##### Share on other sites
You have two open-braces w/o a close-brace, no semi-colon after the last statement, so there's no way to tell really. Won't compile.

By the way, the way you do indenting around here is to use "code" and "/code", but replace the " with [ or ]:
for (int i=0; i<10; i++)  for (int j=0; j<10; j++)    for (int k=0; k<10; k++)      doSomething (i, j, k);

Edited by - Stoffel on 3/8/00 3:34:40 PM

##### Share on other sites
and since i do not know c++ i have no idea what the hell that thing at the bottom of your post is, so if it is supposed to do something then my answer above is probably wrong

##### Share on other sites
I believe the message is meant to mean:

Well, I just went on an interview where I was almost suckered... Here''s a bit of a brainbuster, what will the output be?: (I guess we''re about to find out who''s awake)

int main(int argc, char *argv[]){ int x = 0; char a[26] = {''a'', ''b'', ''c'', ''d'', ''e'', ''f'', ''g'', ''h'', ''i'', ''j'', ''k'', ''l'', ''m'', ''n'',''o'', ''p'', ''q'', ''r'', ''s'', ''t'', ''u'', ''v'', ''w'', ''x'', ''y'', ''z''}; for(int i=0; i < 8; i++) { x += i; cout << x << endl; } return 0;}

I''m adding some blank lines so you can answer the question before you see other people''s answers.

Have fun,
Jon Stelly

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

No sense being pessimistic. It wouldn''t work anyway.