| | |
Setting up counter.
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 13
Reputation:
Solved Threads: 0
So I need to create a set of data points for the function v*t+.5at(squared). The data points need to be every .02 seconds from 0 to 2.0 seconds. How do I set up the counter for that? Also, all of these points need to be wrote to a location so that I can try to graph them. What would be the best way to do that?
Thanks in advance
Thanks in advance
•
•
Join Date: Jun 2007
Posts: 59
Reputation:
Solved Threads: 3
You could try a double variable, like this:
Inside that for, you compute the values for your function, then you save these either in an array of type double, or (if you want them to be available later) into a text file.
C Syntax (Toggle Plain Text)
for (float c=0.0;c<2.1;c+=0.02) { ... }
Last edited by Chaster; Oct 22nd, 2008 at 10:27 am.
Never use this approach in math calculations: 0.02 is a double type approximation of the real number 0.02 so 100*0.02 != 2.0.
In that case you have 100 intervals (and 101 points):
In that case you also have a ready-to-use index to place all needed values in arrays (to plot graph etc)...
To avoid time expensive conversions of i var from int type to double type you can add in the loop header auxiliary double "index" variable. As usually, no need in this optimization...
In that case you have 100 intervals (and 101 points):
c Syntax (Toggle Plain Text)
double t; int i; for (t = 0.0,i = 0; i <= 100; ++i, t = i/50.0) { ..... }
To avoid time expensive conversions of i var from int type to double type you can add in the loop header auxiliary double "index" variable. As usually, no need in this optimization...
![]() |
Similar Threads
- Retrieve Data from a dataset (VB.NET)
- Hit counter (JavaScript / DHTML / AJAX)
- SPIM Assembly HELP!!!! (Assembly)
- Need a little project doing (Web Development Job Offers)
- Timer Control Help (VB.NET)
- Setting Up Game Server (Networking Hardware Configuration)
- PHP Server-Side Hit Counter for Beginner (PHP)
Other Threads in the C Forum
- Previous Thread: Divide and conquer?
- Next Thread: Sorting in C
| Thread Tools | Search this Thread |
#include adobe ansi api append array arrays asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork framework frequency function getlasterror givemetehcodez global grade gtkgcurlcompiling hacking hardware highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user voidmain() wab windows.h windowsapi






