You are not logged in.

#1 2009-05-04 20:55:37

hBd
Member
From: Romania - Cluj Napoca
Registered: 2008-06-08
Posts: 241
Website

Need help for C homework :)

Hello, first of all i dont want to resolv my homework just i need some help.
The probleme is that i need to make two *.c files, one for the function one for the main. The function is a nth root implementation http://en.wikipedia.org/wiki/Nth_root_algorithm and i want to return the value, in main.c want to add the returned value to a variable but not seems to be working.
Sry for my english, i post the source to see what i want.

main.c:

#include <stdio.h>
#include <math.h>

int main()
{
int szam,hatv;
double gy;

printf("Adja meg a kivant szamot: ");
scanf("%d",&szam);
printf("Adja meg a hatvanykitevot: ");
scanf("%d",&hatv);

gy=gyok(hatv,szam);
printf("%3.8lf\n",gy);

return 0;
}

function.c

double gyok(int k, int a)
{
double sz1,sz2;
double e=1E-8;

sz1=(double)a/2;
sz2=sz1;
while ( (pow(sz2,(double)k)-(double)a) > e )
{
    sz2 = (1/(double)k)*(((double)k-1)*sz1+(double)a/pow(sz1,(double)k-1));
    sz1=sz2;
}
return sz2;
}

i compile and link them to one output, and after i run it:

 ./gyok 
Adja meg a kivant szamot: 9
Adja meg a hatvanykitevot: 2
288.00000000

ps. if anything is unclear pls ask, and if i can anwser it tongue
thx

Offline

#2 2009-05-04 22:30:25

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Need help for C homework :)

I've put this up for discussion at the moderator board wink.

In the meantime: you could translate the Rumenian strings so other users can follow too. I'm not savvy enough when it comes to C to see if that makes a difference, but who knows wink.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2009-05-04 22:38:29

hBd
Member
From: Romania - Cluj Napoca
Registered: 2008-06-08
Posts: 241
Website

Re: Need help for C homework :)

B wrote:

I've put this up for discussion at the moderator board wink.

In the meantime: you could translate the Rumenian strings so other users can follow too. I'm not savvy enough when it comes to C to see if that makes a difference, but who knows wink.

it's not Roumanian, its Hungarian (long story tongue) but i will translate tomorrow, coz i need to rest big_smile

Offline

#4 2009-05-04 22:54:30

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Need help for C homework :)

hBd wrote:
B wrote:

I've put this up for discussion at the moderator board wink.

In the meantime: you could translate the Rumenian strings so other users can follow too. I'm not savvy enough when it comes to C to see if that makes a difference, but who knows wink.

it's not Roumanian, its Hungarian (long story tongue) but i will translate tomorrow, coz i need to rest big_smile

lol I was wondering why the text was hungarian...


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#5 2009-05-05 00:07:25

Lexion
Member
Registered: 2008-03-23
Posts: 510

Re: Need help for C homework :)

Why should we help you with your homework?  Shouldn't you do it yourself...


urxvtc / wmii / zsh / configs / onebluecat.net
Arch will not hold your hand

Offline

#6 2009-05-05 01:13:35

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: Need help for C homework :)

I think you need to use fabs()... somewhere... wink

It is easier to just cast once when you pass the function your arguments instead of casting a bunch of times inside the function.  I mean change gyok to "double gyok(double k, double a)" and call it like "gyok( (double)bubble, (double)dragon )".  After you do that and space out the parenthesis it would be easier to see if you made a typo. You don't need both sv1 and sv2, one will do.

Offline

#7 2009-05-05 03:07:41

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: Need help for C homework :)

No homework here...

Closing

Offline

Board footer

Powered by FluxBB