P: 1

a c++ program to solve circle area
 
Share this Question
Expert 100+
P: 1,764

a c++ program to solve circle area
What have you done so far?
Post your code here and someone will help you.
  100+
P: 1,806

I assume you know that:
A = (pi)r^2
If you make a program that implements this formula (pi is approximately 3.1415926535898 > but you mayt be better off using the value in the math library)......
 
P: 5

remember man that in C++ the ' ^ ' symbol doesnt apply. you need to use this formula
A=3.14*pow(R,2);
in pow the number goes first then the power.
  Expert 100+
P: 315

I assume you know that:
A = (pi)r^2
If you make a program that implements this formula (pi is approximately 3.1415926535898 > but you mayt be better off using the value in the math library)......
If it is defined. Standard C does not have a constant for pi. If you need it, you have to define it for yourself (either by using #define or by means of the trigonometric functions).
  100+
P: 1,806

If it is defined. Standard C does not have a constant for pi. If you need it, you have to define it for yourself (either by using #define or by means of the trigonometric functions).
Hence the mention of the math library....which has M_PI
  Expert 100+
P: 315

Hence the mention of the math library....which has M_PI
Every C math lib has M_PI defined?
 
P: 5

can i just say that since floats and doubles(i assume thats what you're using)only allow for 3 digits after the desimal you really dont need an enormously acurate pi. 3.14 should do fine.
  100+
P: 1,806

floats and doubles only allow three places after the decimal?
  Expert 100+
P: 1,764

can i just say that since floats and doubles(i assume thats what you're using)only allow for 3 digits after the desimal you really dont need an enormously acurate pi. 3.14 should do fine.
I think that floats and doubles allow up to six decimal places.
They have a next syntax +/***.******,where * reprsent a integer number
So pi would be:3.141593,which is way more accurate than 3.14.
  Expert 100+
P: 315

I think that floats and doubles allow up to six decimal places.
They have a next syntax +/***.******,where * reprsent a integer number
So pi would be:3.141593,which is way more accurate than 3.14.
No.
Float and double are much more precise than that. Google for IEEE 754.
  Expert 100+
P: 1,764

No.
Float and double are much more precise than that. Google for IEEE 754.
Yes,but I was pointing on default float that have up to six decimal places,if float
is modifed it can show up to 3940 decimal places in c.
I tested this in c by using "%.40f" in printf command.
 
P: 84

Yes,but I was pointing on default float that have up to six decimal places,if float
is modifed it can show up to 3940 decimal places in c.
I tested this in c by using "%.40f" in printf command.
Any idea how to write pi without writing a number, i mean, is there any constant already defined in c++???
 
P: 5

coming back to what i said earlier you can change the number of digits after the decimal.(somthing about setf)but when you cout a float it usually goes to 3
 
P: 99

actually, i believe that the way floats are stored is more like scientific notation; regardless where the decimal point is it is stored as: x.xxxxx^xxx. the decimal point is not at any set point in the number: the location of the decimal is stored in the exponent portion of the variable.
i believe my compiler uses 4 bytes to store a float, so there must be a good few digits stored.
and actually, i read something somewhere once about the continuity of floats. when used to represent a number with many digits before the decimal point, there are fewer digits to make reolution behind the decimal point. so when you plot out the numbers that can be stored in a float, there are places where resolution "thins out" so to speak.
p.s. has anyone heard from the original poster? :)
 
P: 99

or make that that as values get larger (+ or ), the possible float values spread out on the real number line . . . the decimal is pushed out of the picture by a large exponent.
  100+
P: 1,806

couple with that the fact that they are represented in binary (not decimal)......
ie combinations of 1/2 , 1/4,1/8, 1/16, 1/32 etc etc etc
  Expert 100+
P: 315

Any idea how to write pi without writing a number, i mean, is there any constant already defined in c++???
As pointed out earlier in the thread there is no constant for PI defined in standard, but there's M_PI defined in (at least my) math.h.
 
P: 14

If You want a program to find the Area of a circle you can download my program at the fallowing Link removed as per Posting Guidlines . The source codes are also included in the file.
Alexandre Proulx,
 
P: 14

If You want a program to find the Area of a circle you can download a good program at www.alprogramming.wetpaint.com . The source codes are also included in the file so you can check the codes and compile them yourself (Nothing Complicated).
Alexandre Proulx,
 
P: 1

To get Pi I use the following trick:
#include <cmath>
const double Pi = 4 * atan((double)1.0)
    Question stats  viewed: 10670
 replies: 21
 date asked: Mar 17 '07
