Created By rjames93 at 2012/05/06 13:40

https://beta.sucs.org/pb/627 (plain)
  1.   #include "basic.h"
  2.  
  3.   int NumberOfBodies;
  4.  
  5.   struct object{
  6.       double mass;
  7.       double radialdistance;
  8.       double polarangle;
  9.       double azimuthalangle;
  10.       double xcoordinate;
  11.       double ycoordinate;
  12.       double zcoordinate;
  13.       };
  14.  
  15.   struct object * objectarray = NULL;
  16.      
  17.   struct object object;
  18.  
  19.   int i=0;
  20.  
  21.   int input(){
  22.       printf("Insert number of bodies in the System:");
  23.       scanf("%d",&NumberOfBodies);
  24.  
  25.       objectarray = calloc(NumberOfBodies, sizeof(struct object));
  26.  
  27.       if (objectarray == NULL) {
  28.       fprintf(stderr, "No more memory can be allocated \n Hope you like eels! \n");               
  29.   }
  30.  
  31.       for (i=0; i<NumberOfBodies; i++){
  32.           printf("For Body number %d \n",i);
  33.          
  34.           printf("Enter mass of body (kg) %d : \n",i);
  35.           scanf("%lf" , &object.mass);
  36.          
  37.           printf("Enter the, |r|, the radial distance of object %d: \n", i);
  38.           scanf("%lf" , &object.radialdistance);
  39.          
  40.           printf("Enter the polar angle, theta, of object %d: \n", i);
  41.           scanf("%lf" , &object.polarangle);
  42.          
  43.           printf("Enter the azimuthal angle, thi, of object %d: \n", i);
  44.           scanf("%lf" , &object.azimuthalangle);
  45.          
  46.           printf("Converting the coordinates you entered in to Cartesian");
  47.          
  48.           conversion();
  49.  
  50.           objectarray[i] = object;
  51.       }
  52.  
  53.       return(0);
  54.   }
  55.  
  56.   int conversion(){
  57.          
  58.           object.xcoordinate(&object.radialdistance)*cos(&object.azimuthalangle)*sin(&object.polarangle);
  59.          
  60.           object.ycoordinate = (&object.radialdistance)*sin(&object.azimuthalangle)*sin(&object.polarangle);
  61.          
  62.           object.zcoordinate = (&object.radialdistance)*cos(&object.polarangle);
  63.      
  64.       return(0);
  65.   }

You must be logged in to paste new items to the PasteBin