Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 11th, 2012, 09:31 AM
 Matoi
Registered User

Join Date: Nov 2012
Location: ミンダナオ、フィリピン
Posts: 4
Time spent in forums: 2 h 36 m 5 sec
Reputation Power: 0
Problem Help?

Write a problem that will calculate the average velocity and acceleration from a series of measurements for the displacement and time of a falling stone. Find the velocity and acceleration as well.

So far I got this:

Code:
```
#include <stdio.h>
#define N = 5

int main() {

int v[N], a[N];

int d[N] = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6};

int t[N] = {0, 0.05, 0.2, 0.4, 0.8, 1.25, 1.8};

for (x=0;x<7;x++){
v[N] = d[x+1] - d[x] / t[x+1] - t[x];
}

printf ("velocities are %d", v[N]);

for (x=0;x<7;x++){
a[N] = v[x+1] - v[x] / t[x+1] - t[x];
}

printf ("acceleration are %d", a[N]);

system ("pause");

return 0;

}

```

I know I'm still missing something but...yeah. A little help?

#2
December 11th, 2012, 10:10 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,258
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 22 m 54 sec
Reputation Power: 1827
> #define N = 5
The form is
#define N 5

> int d[N] = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6};
You have 7 elements, yet N is 5 ?

> for (x=0;x<7;x++){
Replace 7 with N, when you've decided on whether it's 5 or 7 through your code.

> v[N] = d[x+1] - d[x] / t[x+1] - t[x];
Maybe v[x] as well?
Also, watch out for the x+1 things. You're stepping off the ends of the arrays.

> printf ("velocities are %d", v[N]);
You'll need a for loop to do this, to print each v[x] individually.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Problem Help?