You are not logged in.
Pages: 1
Topic closed
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
thx
Offline
I've put this up for discussion at the moderator board .
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 .
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
I've put this up for discussion at the moderator board .
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 .
it's not Roumanian, its Hungarian (long story ) but i will translate tomorrow, coz i need to rest
Offline
B wrote:I've put this up for discussion at the moderator board .
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 .
it's not Roumanian, its Hungarian (long story ) but i will translate tomorrow, coz i need to rest
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
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
I think you need to use fabs()... somewhere...
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
No homework here...
Closing
Online
Pages: 1
Topic closed