#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <conio.h> #include <dos.h> #define ESC 0x1b #define TAB 0x09 float nums[3][3]={0}, opred=0; char curn[256]; int max(int a,int b) { return a > b ? a : b; } void drawmatrix(int mx,int my) { cleardevice(); setcolor(WHITE); int i,j,tx,ty,maxrl=0,kx=10; int lens[3][3]={0}; int collen[3]={0}; char number[256]; int wh=textwidth("0"); //shirina simvola int ht=textheight("0"); //visota simbola for(i=0;i<3;i++) { for(j=0;j<3;j++) { gcvt(nums[i][j],5,number); lens[i][j]=strlen(number); } } collen[0]=max(max(lens[0][0],lens[0][1]),lens[0][2]); collen[1]=max(max(lens[1][0],lens[1][1]),lens[1][2]); collen[2]=max(max(lens[2][0],lens[2][1]),lens[2][2]); maxrl=collen[0]+collen[1]+collen[2]; line(4,10,4,ht*3); // risuem linii opredelitelya line(maxrl*wh+2*wh+10,10,maxrl*wh+2*wh+10,ht*3); for(i=0;i<3;i++) for(j=0;j<3;j++) { if(i==0) tx=10; else { tx=10+(collen[0]+1)*wh; if(mx-1==1 && my-1==j) kx=tx; if(i==2) { tx+=(collen[1]+1)*wh; if(mx-1==2 && my-1==j) kx=tx; } } ty=j*ht; gcvt(nums[i][j],5,number); outtextxy(tx,ty,number); } opred=nums[0][0]*(nums[1][1]*nums[2][2]-nums[1][2]*nums[2][1]) -nums[1][0]*(nums[0][1]*nums[2][2]-nums[0][2]*nums[2][1]) +nums[2][0]*(nums[0][1]*nums[1][2]-nums[0][2]*nums[1][1]); gcvt(opred,5,number); outtextxy(15+wh*(maxrl+3),ht,"="); outtextxy(15+wh*(maxrl+4),ht,number); // kvadratik gcvt(nums[mx-1][my-1],5,number); setfillstyle(SOLID_FILL,RED); bar(kx,my*ht+2,kx+strlen(number)*wh,my*ht+3); } int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int x=1, y=1, color; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* terminate with an error code */ exit(1); } errorcode = registerbgifont(triplex_font); /* report any registration errors */ if (errorcode < 0) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } settextstyle(TRIPLEX_FONT,HORIZ_DIR,0); // normal code here char ch, symb[2]; //simvol s klavi int nn=0; curn[0]='\0'; drawmatrix(x,y); do { ch=getch(); if(ch==TAB) { // obnulim schetchik dlya vvoda chisla nn=0; curn[0]='\0'; // vichislim tecushii simvol if(x<3) x++; else if(y<3) { x=1; y++; } else { x=1;y=1; } } // esli vvodimie simvoli if((ch>='0' && ch<='9') || ch=='-' || ch=='.') { // dobavim simvol, esli eto vozmogno (dlya '.' i '-') if(!((strlen(curn)!=0 && ch=='-') || (strchr(curn,'.') && ch=='.'))) { curn[nn+1]='\0'; //dobavlyaem simbol curn[nn]=ch; //v konec nn++; nums[x-1][y-1]=atof(curn); } } drawmatrix(x,y); } while (ch!=ESC); // end of normal code /* clean up */ closegraph(); return 0; } |