| | |
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 |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






