![]() |
| | #1 |
| Registered User Join Date: Apr 2004
Posts: 35
| problem with plot a linear graph on the command line Code: /*This program produce real numbers,x and y.
The minimum number for x is 1,... and the maximum
number is 14{...decimal places}because C is 15 spaces " "
The minimum number for y is 1,... and the maximum
number is 24 {...decimal places}because L is 25 spaces " "
C=WIDTH
L=HEIGHT
* * * * * * * * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * * * * * * * *
^
|
(0,0)
*/
#include<stdio.h>
#define WIDTH 15
#define HEIGHT 25
int i;
double my_function(double x);
int main(void)
{
double x_spot,y_spot;
for(i=WIDTH-1;i>0;i--)
{
x_spot=(double)i/WIDTH;
y_spot=my_function(x_spot);
printf("%lf\t%lf\n",x_spot,y_spot);
}
return 0;
}
double my_function(double x)
{
double y;
y=x*x*x+x*x-x+0.2;
if (y>0 && y<HEIGHT)/*only possitive values*/
return y;
}
HOW I CAN PRINT THE GRAPH IN THE BOX? first i run the secondary programm and i place x y values in a *.txt file secondly i scanf the values and finally place for each coordinate one spot at the command line i must convert x and y into integers first (int)x=x_spot*HEIGHT; (int)y=y_spot*WIDTH; I dont understand how i could print the spot for each cordinate starting from the left down corner of the rectangle (0,0) |
| dionys is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,703
| Draw it in memory before you draw it on screen Code: char paper[25][80]; Then do paper[y][x] = '*'; at the points you want to plot When you're done, just print the paper |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Apr 2004
Posts: 35
| explain Draw it in memory before you draw it on screen Code: char paper[25][80]; Start by filling this with spaces Then do paper[y][x] = '*'; at the points you want to plot My dimensions are 15*25..(what is 80 for?) |
| dionys is offline | |
| | #4 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,703
| It's for you to read between the lines and apply it to your specific situation If you can't change char paper[25][80]; into char paper[15][25]; I can't help you |
| Salem is offline | |
| | #5 |
| Registered User Join Date: Apr 2004
Posts: 35
| Sorry sorry ! ![]() I REALLY APRECIATE YOUR HELP SALEM THANKS A LOT ): |
| dionys is offline | |
| | #6 |
| Registered User Join Date: Apr 2004
Posts: 35
| Salem what is wrong? Code: #include<stdio.h>
#define WIDTH 25
#define HEIGHT 15
int main(void)
{
char star='*',space=' ';
int y,x,c;
double y_spot,x_spot;
char my_graph[WIDTH][HEIGHT];
for(y=0;y<HEIGHT;y++)
{
for(x=0;x<WIDTH;x++)
{
my_graph[y][x]=star;
}
}
do{
c=scanf("%lf %lf\n",&y_spot,&x_spot);
y_spot*=HEIGHT;
x_spot*=WIDTH;
my_graph[(int)x_spot][(int)y_spot]=space;
}while(c!=EOF);
for(y=0;y<HEIGHT;y++)
{
for(x=0;x<WIDTH;x++)
{
printf("%c",my_graph[y][x]);
}
printf("\n");
}
return 0;
}
0.866667 0.735407 0.800000 0.552000 0.733333 0.398815 0.666667 0.274074 0.600000 0.176000 0.533333 0.102815 0.466667 0.052741 0.400000 0.024000 0.333333 0.014815 0.266667 0.023407 0.200000 0.048000 0.133333 0.086815 0.066667 0.138074 The y x spots |
| dionys is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bin packing problem.... | 81N4RY_DR460N | C++ Programming | 0 | 08-01-2005 05:20 AM |
| Problem using DFS with a DAG graph | incognito54 | C Programming | 2 | 05-11-2005 06:16 AM |
| C / OpenGL help REALLY needed for simple but annoying problem! | Oz_joker | C Programming | 5 | 12-03-2003 05:47 PM |
| Problem with Hash Table Linear Probing | kirby1024 | C Programming | 5 | 10-23-2002 06:03 AM |
| problem with output | Garfield | C Programming | 2 | 11-18-2001 08:34 PM |