|
-
November 4th, 2009, 05:45 PM
#1
Code
Hey i need help creating a code that calculates volume/surface area of a sphere, i was using this code as a reference but I'm just drawing a blank right now, any help would be appreciated:
//INCLUDE SECTION
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
//DEFINE STATEMENT
#define d(x1,y1,x2,y2) sqrt(pow((x2-x1),2)+ pow((y2-y1),2))
//FUNCTION PROTOTYPE
float distance(float a,float b,float c,float d);
int main(void)
{
//VARIABLE DECLARATIONS
float x1,y1,x2,y2,d_tot;
//EXPLAIN TO USER
system ("cls");
puts("This program will calculate the distance between 2 points");
puts("in space. You will be asked for (x1,y1) (x2,y2) and then");
puts("it will calculate and ouput the distance between these");
puts("points.");
puts("");
//GET USER INPUT
printf("(x1 y1)==>");
fflush(stdin);
scanf("%f%f",&x1,&y1);
printf("(x2 y2)==>");
fflush(stdin);
scanf("%f%f",&x2,&y2);
//CALCULATIONS
d_tot=distance(x1,y1,x2,y2);
//OUTPUT
printf("\n\n(x1,y1) =(%.1f,%.1f)",x1,y1);
printf("\n\n(x2,y2) =(%.1f,%.1f)",x2,y2);
printf("\n\nTotal distance=%.1f",d_tot);
getch();
return 0;
}
//FUNCTION DEFINITIONS
float distance(float a,float b,float c,float d)
{
return(d(a,b,c,d));
}
I need to use these functions in there:
explain();
get_radius();
calc_display();
and i also need to use a define statement for both formulas.
*note* VOLUME of a SPHERE = ( 4 / 3 ) * * radius 3
SURFACE AREA of a SPHERE = 4 * * radius 2
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|