please do this for me

A

amey1.kamat

I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?
int func (int (*)(int) , int);
int cube(int n)
{
return (n*n*n);
}
int main()
{
prinf("%d" , func(cube , 4));
}
int func(int (*tmp)(int in) , int n)
{
int res , i;
for(i = 1 ; i <= n ; i++)
res += *(tmp)(i);
return res;
}
 
S

santosh

I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?

<snip>

You've not cut and pasted the actual code, (likely since I spotted a
'prinf' instead of printf).

The program as given is broken.
 
B

Barry

I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?
int func (int (*)(int) , int);
int cube(int n)
{
return (n*n*n);
}
int main()
{
prinf("%d" , func(cube , 4));

No such thing as prinf.
}
int func(int (*tmp)(int in) , int n)
{
int res , i;
for(i = 1 ; i <= n ; i++)
res += *(tmp)(i);

Probably (*tmp)(i);
return res;
}

And the "error" you are probably asking
about is
res in not initialized.
 
C

christian.bau

I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?

My company does that kind of thing for job interviews.

Step 1: Get through some online problems.
Step 2: Go through a phone interview.
Step 3: Go to a real interview.

Step 1 is there so we don't waste your time and our time in Step 2.
Cheating is quite pointless, because if you have to cheat in an online
interview, you won't make it through the phone interview anyway.
(First question in the phone interview: What does the first line in
that program do? )
 
C

Christopher Benson-Manica

Can someone explain me what this code should do?and whats the error?

Hm, if you can't be bothered to run a compiler to solve an online
quiz, why would anyone assume you could be bothered to be paid to run
one? There are at least 5 errors in the code you posted.

(The code is not complicated. Make another pass through K&R before
you apply for any other jobs.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,166
Latest member
DollyBff32
Top