Hello everyone. I just finished answering these coding problems and was wandering if you guys could look over them to see if they are done correctly. Thanks so much!
In the following problems, what does the given function return?
Problem 1
1 2 3 4 5 6 7 8 9 10 11 12
int foo(void)
{
int i, j, k, x = 0;
for ( i = 5; i >0 ,i -= 3)
for (j = 3; j*2 < 10; j++)
for (k=7; k+j < 14; k++)
{ x += 2;
x += 3;
}
return (x);
}
#include <iostream>
#include <string>
usingnamespace std;
int foo (void);
int n;
int z;
int main()
{
cout<< z<< endl;
}
int foo(void)
{
int i, j, k, x = 0;
for ( i = 5; i >0 ,i -= 3;)
for (j = 3; j*2 < 10; j++)
for (k=7; k+j < 14; k++)
{ x += 2;
x += 3;
}
x = z;
return (z);
}
I set it up so that return =z but it said z equals 0 when i ran it. Could this possibly be right?
#include <iostream>
#include <string>
usingnamespace std;
int foo (void);
int main()
{
cout<< foo() << endl;
}
int foo(void)
{
int i, j, k, x = 0;
for ( i = 5; i >0 ,i -= 3;)
for (j = 3; j*2 < 10; j++)
for (k=7; k+j < 14; k++)
{ x += 2;
x += 3;
}
return (x);
}
#include <iostream>
#include <string>
using namespace std;
int foo (void);
int main()
{
cout<< foo() << endl;
}
int foo(void)
{
int i, j, k, x = 0;
for ( i = 5; i >0 ,i -= 3;)
for (j = 3; j*2 < 10; j++)
for (k=7; k+j < 14; k++)
{ x += 2;
x += 3;
}
return (x);
}
I tried running it the way you wrote it above^^. It ran but gave me no output. It was just blank. Does anyone know what I need to add or do to see what x is equal to?
But when I take away the colon it gives me a syntax error. Does anyone know how I can run the function and just see the return value? That is all I really want to check. There must be a way to do it. Thanks.