Jump to content

Programming Assignment Help- Urgent

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
MythKissbrownie

MythKissbrownie

    Newbie

  • Members
  • Pip
  • 3 posts
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

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
What have you got so far?
Wow I changed my sig!

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You'll need to use the math.h library to get access to sqrt() and cos()
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
MythKissbrownie

MythKissbrownie

    Newbie

  • Members
  • Pip
  • 3 posts
# 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
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
v = A * √(k/m) * cos (√(k/m) * t)
v = A* sqrt(k/m) * cos(sqrt(k/m)*t);
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
MythKissbrownie

MythKissbrownie

    Newbie

  • Members
  • Pip
  • 3 posts
#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
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,716 posts
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 /