#include #include #define MAX_COLUMNS 60 float xl, xu, delta, ymin, ymax; int ch; void print_header(); void get_domain_parameters(); void calculate_min_max(); void print_plot_header(); void print_plot_footer(); void print_plot(); double expon(double,int); double fac(int); double expp(double); main() { print_header(); get_domain_parameters(); calculate_min_max(); print_plot(); return 0; } double func(double x) { if(ch==1) return sin(x); else if(ch ==2) return cos(x); else if(ch ==3) return sin(x)*cos(x); else return expp(x); } double expon(double x, int m) { int j; double num = 1; for(j=0;j ymax) ymax = y; } } void print_plot_header() { printf(" %3.1f", ymin); printf(" %3.1f", (ymin + ymax) / 2); printf(" %3.1f\n", ymax); printf(" +"); printf("-----------------------------+"); printf("------------------------------+\n"); } void print_plot_footer() { printf(" +"); printf("-----------------------------+"); printf("------------------------------+\n"); printf(" %3.1f", ymin); printf(" %3.1f", (ymin + ymax) / 2); printf(" %3.1f\n", ymax); } void print_plot() { int scale_index, i, previous; float x; char A[MAX_COLUMNS]; for (i = 0; i < MAX_COLUMNS; i++) A[i] = ' '; x = xl; previous = 0; print_plot_header(); /*************************************************************/ /* Loop through values of x in the domain, in incs of delta */ /*************************************************************/ while (x <= xu) { /***********************************************************/ /* Calculate scale_index: number of spaces to the left of */ /* the asterisk. Keep track of previous location of the */ /* asterisk. In each iteration, place a space in the */ /* previous location, and an asterisk in the current one. */ /***********************************************************/ scale_index = (func(x) - ymin) * MAX_COLUMNS / (ymax - ymin) - 0.5; A[previous] = ' '; A[scale_index] = '*'; previous = scale_index; printf("%5.2f |", x); for (i = 0; i < MAX_COLUMNS; i++) putchar(A[i]); printf("|\n"); x = x + delta; } print_plot_footer(); }