By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,131 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,131 IT Pros & Developers. It's quick & easy.

computer problem...

Bigj0410
P: 26
i was working on a couple program questions and apparently...my PC has a virus....so right now i'm on a friends PC where he doesn't have any C++ programs....so i was just wondering what are the outputs of these programs below...thx in advance ;)

(program 1)

char x[3] = {0, 1, 2} ;
int y[3];
for (int i = 0 ; i < 3 ; i++)
{
y[i] = x[i] ;
cout << x[i] << "\t" <<y[i]<< endl;
}

(program 2)

#include <iostream>
using namespace std;
long int mystery(int, int);
int main()
{
int in1, in2;
cout << "Enter two integers: ";
cin>>in1>>in2;
cout <<"The result is " << mystery (in1, in2)<<endl;
return 0;
}
//parameter b must be a positive
long int mystery (int a, int b)
{
if (b==1)
return a;
else
return a + product(a, b-1);
}
Feb 22 '07 #1
Share this Question
Share on Google+
5 Replies


DeMan
100+
P: 1,806
Surely the idea is for you to step through the code and try to see if you can see what's going on?

The first one is very simple, have a think about what is being done. (The cout line is the one that does the printing./.....)

the key here is to follow the code through the method calls. I am assuming that product(int, int) is defined somewhere?......
Feb 22 '07 #2

Bigj0410
P: 26
Surely the idea is for you to step through the code and try to see if you can see what's going on?

The first one is very simple, have a think about what is being done. (The cout line is the one that does the printing./.....)

the key here is to follow the code through the method calls. I am assuming that product(int, int) is defined somewhere?......
yea...but i don't know where though
Feb 22 '07 #3

Ganon11
Expert 2.5K+
P: 3,652
I have a feeling that the function call is supposed to be mystery(a, b-1) rather than product(a, b-1).
Feb 22 '07 #4

Bigj0410
P: 26
I have a feeling that the function call is supposed to be mystery(a, b-1) rather than product(a, b-1).
...ok....right now my PC is getting checked...thx 4 da info
Feb 22 '07 #5

Bigj0410
P: 26
ok...now it works
Feb 22 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.