LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-20-2005, 04:23 AM   #1
donotexpert
LQ Newbie
 
Registered: Aug 2005
Location: thai
Posts: 4

Rep: Reputation: 0
please help my homework again


#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.
 
Old 08-20-2005, 04:29 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,427

Rep: Reputation: 51
We don't help people do their homework. Why don't you tell us which part you don't understand and we'll go from there.

-twantrd
 
Old 08-20-2005, 04:35 AM   #3
donotexpert
LQ Newbie
 
Registered: Aug 2005
Location: thai
Posts: 4

Original Poster
Rep: Reputation: 0
ok

-who expert please tell me please
 
Old 08-20-2005, 08:00 AM   #4
Orkie
Member
 
Registered: Mar 2005
Distribution: Breezy Badger
Posts: 248

Rep: Reputation: 30
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!
 
Old 08-20-2005, 04:01 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,408

Rep: Reputation: 108Reputation: 108
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.
 
Old 08-20-2005, 09:11 PM   #6
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
... and remember to always, *always* post your code in those damned code tags!

--Jonas
 
Old 08-20-2005, 09:17 PM   #7
aysiu
Senior Member
 
Registered: May 2005
Distribution: Ubuntu with IceWM
Posts: 1,776

Rep: Reputation: 47
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.
 
Old 08-23-2005, 10:26 AM   #8
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,685

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
Thumbs down

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on Homework... Cant find .bashrc maravillasc Linux - Newbie 11 10-17-2005 09:39 PM
Linux homework Ghstfce Linux - General 7 09-09-2005 04:39 AM
homework help louce Linux - Newbie 3 09-04-2005 08:00 PM
help me(my homework) please! donotexpert Programming 4 08-20-2005 06:26 AM
Need homework help! bumstickie Linux - Newbie 3 10-28-2002 04:37 AM


All times are GMT -5. The time now is 06:47 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration