The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Problem Help?
Discuss Problem Help? in the C Programming forum on Dev Shed. Problem Help? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 11th, 2012, 08:31 AM
|
|
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?
|

December 11th, 2012, 09:10 AM
|
 |
Contributed User
|
|
|
|
|
> #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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|