C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
subject area of cirlce. Posted by talhanasir on 1 Jun 2006 at 3:53 AM
what is meaning of double-precision in the following question?

Write a function that returns the double-precision area of a circle, given the double precision radius passed to it. The formula to calculate the radius of a circle is .

area = 3.14159 * radius * radius.

what will be the value of radius.?


and what will be the value of radius in above question?
Talha Nasir

Report
Re: subject area of cirlce. Posted by HK_MP5KPDW on 1 Jun 2006 at 4:41 AM
: what is meaning of double-precision in the following question?
:
: Write a function that returns the double-precision area of a circle, given the double precision radius passed to it. The formula to calculate the radius of a circle is .
:
: area = 3.14159 * radius * radius.
:
: what will be the value of radius.?

:
: and what will be the value of radius in above question?
: Talha Nasir
:
:

Use double variables as opposed to float for radius and area. How the heck do I know what the value of radius is going to be? I'm not clairvoyant/omniscient.
Report
Re: subject area of cirlce. Posted by IDK on 1 Jun 2006 at 5:39 AM
: : what is meaning of double-precision in the following question?
: :
: : Write a function that returns the double-precision area of a circle, given the double precision radius passed to it. The formula to calculate the radius of a circle is .
: :
: : area = 3.14159 * radius * radius.
: :
: : what will be the value of radius.?

: :
: : and what will be the value of radius in above question?
: : Talha Nasir
: :
: :
: How the heck do I know what the value of radius is going to be? I'm not clairvoyant/omniscient.[/green]
:
With some math it should be:
raduis = sqrt(area / 3.14159)
Report
Re: subject area of cirlce. Posted by zeolite on 1 Jun 2006 at 8:03 AM
That should be exactly what you need:
double AreaOfCircle(double radius)
{
  return 3.14159 * radius * radius;
}


: what is meaning of double-precision in the following question?
:
: Write a function that returns the double-precision area of a circle, given the double precision radius passed to it. The formula to calculate the radius of a circle is .
:
: area = 3.14159 * radius * radius.
:
: what will be the value of radius.?

:
: and what will be the value of radius in above question?
: Talha Nasir
:
:
Report
Re: subject area of cirlce. Posted by FDrache on 2 Jun 2006 at 9:08 AM
: That should be exactly what you need:
double AreaOfCircle(double radius)
: {
:   return 3.14159 * radius * radius;
: }

:

That's it! And to be exact, define and take
const double pi = 2.0 * acos(0.0); // 2*arccosine(0)
because pi is usually not defined in C libraries.
FDrache.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.