C/C++ Brainbuster.
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
Sorry, formatting is terrible here... How the hell do I indent something? bleh
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++
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 ]:
Edited by - Stoffel on 3/8/00 3:34:40 PM
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
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
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)
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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Link
No sense being pessimistic. It wouldn''t work anyway.
===========================There are 10 types of people in the world. Those that understand binary and those that don't.( My views in no way reflect the views of my employer. )
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement