Try to search your question here, if you can't find : Ask Any Question Now ?

How to generate total kinetic energy and total potential energy of the generated particles in c++ code?

HomeCategory: stackoverflowHow to generate total kinetic energy and total potential energy of the generated particles in c++ code?
Avatarkundan asked 6 days ago

I need a program that will generate 100 random particle positions (x,y,and z) and the generates random velocities then takes those velocities and finds the total kinetic energy and total potential energy.

I am stuck on how to get the total kinetic energy and total potential energy
This is what I have so far and it will generate the positions and velocities.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>

using namespace std;
int main()
 {
     int q, x, y, z, Q, x1, y1, z1;
     printf("Enter the number of particles: n");
     scanf("%d", &q);
     srand(time(NULL));
     printf("The positions of the particles are:n x: y: z:n");
     for (int i=0; i<= q; i++)
     {
         int x=rand()%100;
         int y=rand()%100;
         int z=rand()%100;
         printf("%d %d %d n", x, y, z);
     }
     printf("Enter number of velocities: n");
     scanf("%d", &Q);
     srand(time(NULL));
     printf("The velocities are:n x1: y1: z1:n");
     for (int i=1; i<=Q; i++)
     {
         while (true)
         {
             x1=rand()%225;
             y1=rand()%225;
             z1=rand()%225;
             if(((x1*x1)+(y1*y1)+(z1*z1))<= 225)
                break;
         }
         cout<<x1<<"t"<<y1<<"t"<<z1<<endl;
     }
return 0;
}
1 Answers
Best Answer
AvatarMikhail answered 6 days ago
Your Answer

15 + 9 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com