#include <iostream>
// Required to calculate pi more accurately:
//#include <math.h>
int main()
{
const double pi = 3.14;
// To calculate pi more accurately, use:
// const double pi = 4*atan(1.0);
double r;
while( 1 )
{
printf( "Calculate the area of a circle.\n" );
printf( "Enter 0 to exit.\n" );
printf( "Enter the circle's radius: " );
if( std::cin >> r )
{
if( !r )
{
printf( "\n" );
break;
}
printf( "Area of circle is: %.2f\n\n", pi * r * r );
}
else
{
printf( "Invalid input. Please try again.\n\n" );
std::cin.clear();
while( std::cin.get() != '\n' ) ;
}
}
return( 0 );
}
your mom nothing
I'm not sure how you'd do this in C++, but I could have a go at it in php since that's what I know. You know that Pi is approximately 22/7, in php you can use the pi function. You'd need your input(radius) to come from a form if it was web-based, which is simple enough. perimeter = 2nr = 2 x (22/7) x r function getPerimeter ($input) { $input = $_GET['formInput']; $pi=pi(); $perimeter = (2*$pi)*$input; return $perimeter; } HTH
public void getPoint(double r, double angle) { //cosine*hypotenuse=adjasent double x = r * Math.cos (Math.toRadians(angle))//in radians; //sine * hypotenuse =opposite double y=r*Math.sin(Math.toRadians(angle))//also in radians; System.out.println("( "+x+", "+y+" )"); }
You use the diameter formular. You know, C=pi(d). If you know the cicumference, then you use this equation, d=c/pi. You subsitute the cimcumference and divide (pi=3.14), and that's how you calculate dimater. Oh yeah, and if your given the radius of the circle, just multiply it by two.Type your answer here...
There are several options to draw a circle using C or C++ without the built-in functions... <> <> <> <> If you can draw a single pixel at a time, use a for loop to iterate Angle from 0 to 2*pi. Then plot a pixel with x=cos(Angle) and y=sin(Angle). Smaller steps will give better results. Lines from one point to the next may look nicer. Generally, you can use a line from one pixel to the next to draw a polygon. The number of sides is determined by the number of steps from 0 to 2*pi. A circle is a polygon with an "infinite" number of sides (compared to the display resolution). Experiment with non-integral steps to see that the polygon can end at any place. Use an integral number of steps to end where the circle began. Start and stop at fractions of 2*pi, or step backwards, to create arcs. Speed up the code by using lookup tables to calculate sin() and cos(). Hint: they can be the same table, and don't need to be a complete 2*pi circle. <> <> <> <> You can also draw the circle without the sin() and cos() functions if you understand the trigonometry behind sin() and cos(). Recall that sin(theta) is radius / y, and cos(theta) is radius / x, given that x and y are the two sides of a right triangle and that radius is the hypotenuse. By Pythagoream's theorem, x2 + y2 is radius2. It is then simple to solve for x or y, given the other along with radius. You also do not need to compute for the whole circle - you can compute for one quadrant, and generate the other three quadrants by symmetry. You generation loop would, for example, simply iterate from origin to radius as x by delta x, generating y, and reflecting that in the other three quadrants. You can also compute for one half of a quadrant, and use both symmetry and reflection to generate the other seven half quadrants.
you cant: pi is the same for any circle - 3.1415... the diamter or the radius has to be given diameter divided by two equals the radius the radius times two equals the diameter
Half the square root of the square radius equals the circle radius.
Circumference equals the diameter times pi. The diameter is 2 times radius. Radius equals Circumference divided by pi then divided by 2.
Diameter of a circle = 2*radius Circumference of a circle = 2*radius*pi
Given the circumference of a circle the radius is: r = C / 2xPI So the radius of your circle is 326.7451 ft
if you are given the circle's "height" then that is the diameter. the diameter is twice the length of the radius, so divide the height by two and you will get the radius.
Double the radius
Radius = Diameter/2.
Circumference of a circle given radius Area of a circle given radius Volume of a sphere given radius Surface area of a sphere given radius Converting degrees to radians or vice versa
By using the other information supplied about the circle to calculate either its radius (from which its area can be calculated) or its area (if the circle is similar to another with a given area and some ratio between the two circle is given):If the diameter is given: radius = diameter ÷ 2If the circumference is given: radius = circumference ÷ 2πIf the circle is similar to another circle which has a given area, and the length ratio is given; square the length ratio to get the area ratio and apply to the given area.
If you are given the radius of the circle, you can use the formula: diameter = 2*radius If you are given the circumference of the circle, you can use the formula: diameter = circumference/pi
The longest chord in a circle is its diameter and halve of this is its radius.