It looks you intended to use
arr
as a screen buffer, but in the end the code handles it incorrectly (it should find the ranges for both
x
and
y
and then scale them appropriately to the screen buffer)
Try
#include <float.h>
#include <stdio.h>
#define scanf_s scanf
#define SCREEN_BUFFER_ROWS 100
#define SCREEN_BUFFER_COLS 80
void show_screen_buffer(char * screen_buffer, size_t rows, size_t cols );
int main()
{
int a, b, c, d, e, f;
printf("please input six coefficients\n");
scanf_s("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
printf("%d %d %d %d %d %d\n", a,b,c,d,e,f);
int x1, x2;
printf("please input range of x1-x2\n");
scanf_s("%d%d", &x1, &x2);
printf("%d %d\n", x1, x2);
int xt;
printf("please input x value 0f tangent point\n");
scanf_s("%d\n", &xt);
printf("%d\n", xt);
double ymax, ymin;
double xmax, xmin;
ymax = DBL_MIN;
ymin = DBL_MAX;
xmax = x2;
xmin = x1;
int row, col;
int i;
for ( i = 0; i < (x2-x1); ++i)
{
double x = i + x1;
double y = f + e * x + d * (x*x) + c * (x*x*x) + b * (x*x*x*x) + a * (x*x*x*x*x);
if ( ymin > y) ymin = y;
if ( ymax < y) ymax = y;
}
int screen_buffer[SCREEN_BUFFER_ROWS] [SCREEN_BUFFER_COLS] = {0};
for ( i = 0; i < (x2-x1); ++i)
{
double x = i + x1;
double y = f + e * x + d * (x*x) + c * (x*x*x) + b * (x*x*x*x) + a * (x*x*x*x*x);
row = (SCREEN_BUFFER_ROWS -1) * (x -xmin) / (xmax-xmin);
col = (SCREEN_BUFFER_COLS -1) * (y -ymin) / (ymax-ymin);
screen_buffer[row][col] = 1;
}
for (row= 0; row < SCREEN_BUFFER_ROWS; ++row)
{
for (col=0; col < SCREEN_BUFFER_COLS; ++col)
putchar( screen_buffer[row][col] ? '*': ' ');
putchar('\n');
}
return 0;
}
With your suggested inputs, it produces, on my system:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*