- #include "basic.h"
- int NumberOfBodies;
- struct object{
- double mass;
- double radialdistance;
- double polarangle;
- double azimuthalangle;
- double xcoordinate;
- double ycoordinate;
- double zcoordinate;
- };
- struct object * objectarray = NULL;
- struct object object;
- int i=0;
- int input(){
- printf("Insert number of bodies in the System:");
- scanf("%d",&NumberOfBodies);
- objectarray = calloc(NumberOfBodies, sizeof(struct object));
- if (objectarray == NULL) {
- fprintf(stderr, "No more memory can be allocated \n Hope you like eels! \n");
- }
- for (i=0; i<NumberOfBodies; i++){
- printf("For Body number %d \n",i);
- printf("Enter mass of body (kg) %d : \n",i);
- scanf("%lf" , &object.mass);
- printf("Enter the, |r|, the radial distance of object %d: \n", i);
- scanf("%lf" , &object.radialdistance);
- printf("Enter the polar angle, theta, of object %d: \n", i);
- scanf("%lf" , &object.polarangle);
- printf("Enter the azimuthal angle, thi, of object %d: \n", i);
- scanf("%lf" , &object.azimuthalangle);
- printf("Converting the coordinates you entered in to Cartesian");
- conversion();
- objectarray[i] = object;
- }
- return(0);
- }
- int conversion(){
- object.xcoordinate = (&object.radialdistance)*cos(&object.azimuthalangle)*sin(&object.polarangle);
- object.ycoordinate = (&object.radialdistance)*sin(&object.azimuthalangle)*sin(&object.polarangle);
- object.zcoordinate = (&object.radialdistance)*cos(&object.polarangle);
- return(0);
- }
You must be logged in to paste new items to the PasteBin