Hello,
I am completely new to programming and I would like help with writing this program:
At time t, the velocity of an object undergoing simple harmonic motion at the end of a spring is given by the formula
v = A * √(k/m) * cos (√(k/m) * t)
m=mass of object (in g),
k=constant depending on the spring (in g/s^2),
A=maximum distance object moves
t=time (in s)
Write a C program which accepts as inputs a time t, mass m, constant k, and distance A, and which computes the velocity of the object according to the formula above.
Can someone pleace exlain step by step. Thank you
Programming Assignment Help- Urgent
Started by MythKissbrownie, Sep 19 2009 01:03 PM
6 replies to this topic
#1
Posted 19 September 2009 - 01:03 PM
|
|
|
#2
Posted 19 September 2009 - 01:14 PM
#3
Posted 19 September 2009 - 01:48 PM
You'll need to use the math.h library to get access to sqrt() and cos()
#4
Posted 19 September 2009 - 05:56 PM
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main () {
double t, m, k, A, v;
printf ("Enter t\n");
scanf ("%lf", &t);
printf ("Enter m\n");
scanf ("%lf, &m);
printf ("Enter k\n");
scanf ("%lf", &k);
printf ("Enter A\n");
scanf ("%lf", &A);
temp1=sqrt ((double)k\m);
..........not sure bout temp 2..... correct my mistakes?....and the rest
Edited by Jaan, 20 September 2009 - 01:42 AM.
Please use code tags when you are posting your codes !
#5
Posted 19 September 2009 - 06:17 PM
v = A * √(k/m) * cos (√(k/m) * t)
v = A* sqrt(k/m) * cos(sqrt(k/m)*t);
v = A* sqrt(k/m) * cos(sqrt(k/m)*t);
#6
Posted 19 September 2009 - 08:11 PM
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double t, m, k, A, v;
printf ("Please enter m \n");
scanf ("%lf", &m);
printf ("Please enter A \n");
scanf ("%lf", &A);
printf ("Please enter t \n");
scanf ("%lf", &t);
printf ("Please enter k \n");
scanf ("%lf", &k);
v = A * sqrt(k / m) * cos(sqrt(k / m)*t);
printf ("v is: %8.2f \n", v);
system ("PAUSE");
return 0;
}
makes sense? lol :)
Edited by Jaan, 20 September 2009 - 01:44 AM.
Please use code tags when you are posting your codes !
#7
Posted 20 September 2009 - 05:37 PM
system ("PAUSE");
I wouldn't do that...it's not portable at all. Depending on how strict your teacher is they may dock you points for that. Considering the assignment, though, I don't think you need to worry all that much at this point. Just for future reference.
sudo rm -rf /


Sign In
Create Account

Back to top









