ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
#include <stdio.h>
#define c_sub(a,b) c_add(a,-(b))
long c_add(long a,long b)
{
long c,i0,i1,i2,i;
c=i0=i1=0;
i2=1;
for (i=0;i<32;i++) {
i0 = ((a>>i)&1) +
((b>>i)&1) + i1;
if (i0&1) c += i2;
i1 = ((i0>1)&1);
i2 = (i2 << 1);
}
return c;
}
long c_mult(longa,long b)
{
long c,i;
c=0;
for (i=0;i<b;i++)
c = c_add(c,a);
return c;
}
long c_power(long a,long b)
{
long c,i;
c=1;
for (i=0;i<b;i++)
c = c_mult(c,a);
return c;
}
long c_div(long a,long b)
{
long c,i;
c=0;
while (a>b) {
a = c_sub(a,b);
c = c_add(c,1);
}
return c;
}
long c_fact(long a)
{
long c,i;
c=1;
for (i=1;i<=a;i++)
c = c_mult(c,i);
return c;
}
long f1(int a)
{
long c,i;
c=0;
for (i=0;i<=a;i++)
c = c_add(c,c_fact(i));
return c;
}
long f2(long n,long seed)
{
long c,i;
if (n==0)
return c_power(seed,2);
else
// 2*n^2 + 5*n + 3*f2(n-1)/2
return (c_add(c_add(c_mult(2,
c_power(n,2)),c_mult(5,n)),
c_div(c_mult(3,f2(n-1,seed)),2)));
}
intmain(void)
{
inti;
printf("\n\n");
for (i=5;i<=10;i++) {
printf("f1(%3d)=%10ld\n",i,f1(i));
}
printf("\n");
for (i=10;i<50;i++)
printf("f2(%4d,%4d)=%10ld\n",
i,i,f2(i,i));
return 0;
}
a)Modify the given program and its functions so that we can create a table T[15,15] such that:
–T[i,j] = f2(i,5*j+20)
–The program must spread the work to its child process so that each process computer T[*,j].
a)Modify the program so that at the end, it can report the time spent in each function and the number of times each function is called.
b)Verify the correctness of (b) with “gprof”program.
As twantrd said, tell us what bit you are stuck on and we may be able to explain it to you. There is no point in somebody just doing it for you -- you wouldn't be learning anything then!
donotexpert,
We don't usually help with homework questons (rules: http://www.linuxquestions.org/rules.php). We can give you hints or help you with problems when doing your homework -- but only problems, not the whole thing.
Show us what you have tried to and the results you had.
As a former teacher, I think you should be ashamed. I'm proud of this community for not "helping" you with your homework. Have some academic integrity. Do it yourself. If you're stuck, you can ask for help then. Geez.
I agree. You are only cheating yourself. And, guess what! You cannot be the only one in the classroom who is similarly "stuck," but the teacher has no way to know it unless you ask.
Computer programming is a difficult subject that requires constant practice. The object is not to "get someone else to do it for you," but to learn how to do it yourself.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.