#include #include #include #include #define MAX 100 int n,i,j, N, which,count; float x[100], y[100], X, X2, Y, XY, a,b,sum,dev; char input[10], output[10]; FILE *fptr; int main(){ initscr(); echo(); resize_term(40,80); if(!has_colors()){ endwin(); exit(0); } if(start_color() != OK){ endwin(); exit(0); } init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(0, COLOR_WHITE, COLOR_BLACK); init_pair(4, COLOR_BLACK, COLOR_YELLOW); init_pair(5, COLOR_CYAN, COLOR_BLACK); move(1, 10); attron(A_UNDERLINE); printw("Regression analysis"); attroff(A_UNDERLINE); move(3, 1); printw("Interactive mode (i) or read from file (f)? "); attrset(COLOR_PAIR(2)); getstr(input); attrset(COLOR_PAIR(0)); which=-1; if(strcmp(input,"i")==0 || strcmp(input,"I")==0) which=0; if(strcmp(input,"f")==0 || strcmp(input,"F")==0) which=1; if(which==-1){ move(5,1); printw("Don't prompt OR read from file, bye-bye!"); refresh(); endwin(); exit(0); } if(which==0){ move(5,1); printw("How many (x,y) pairs do you want to enter? "); attrset(COLOR_PAIR(2)); getstr(input); attrset(COLOR_PAIR(0)); N=atoi(input); if(N<0 || N>100){ move(7,1); printw("Sorry, thats out of range"); refresh(); endwin(); exit(0); } count=0; for(i=0;i<=N/2;i++){ for(j=0;j<2;j++){ if(count <= N-1){ move(9+2*i, 28*j); printw("x[%d]= ", count+1); attrset(COLOR_PAIR(1)); getstr(input); attrset(COLOR_PAIR(0)); x[count]=atof(input); move(9+2*i, 28*j+14); printw("y[%d]= ", count+1); attrset(COLOR_PAIR(1)); getstr(input); attrset(COLOR_PAIR(0)); y[count]=atof(input); count=count+1;} } } N=count; move(11+2*N/2, 1); X=0.0; Y=0.0; X2=0.0; XY=0.0; for(i=0;i100){ move(7,1); printw("Sorry, too many data points"); refresh(); endwin(); exit(0); } count=0; for(i=0;i<=N/2;i++){ for(j=0;j<2;j++){ if(count <= N-1){ move(9+2*i, 30*j); printw("(x[%d],y[%d])= ", count+1,count+1); attrset(COLOR_PAIR(1)); printw("(%4.3f, %4.3f)", x[count],y[count]); attrset(COLOR_PAIR(0)); count=count+1;} } } N=count; move(11+2*N/2, 1); X=0.0; Y=0.0; X2=0.0; XY=0.0; for(i=0;i to quit "); attrset(COLOR_PAIR(1)); getstr(input); endwin(); exit(0); }