Red de conocimiento informático - Conocimiento del nombre de dominio - Cómo escribir una pequeña calculadora en lenguaje C

Cómo escribir una pequeña calculadora en lenguaje C

# incluir & ltstdlib.h & gt

# incluir & ltmath.h & gt

# incluir & ltgraphics.h & gt

# incluir & ltstdio. h & gt

# include & ltprocess.h & gt

#Definir EXCAPE 27

#Definir entrada 13

main() {

int prensa, I, x, y, x1, y1, ch_z = 0

int Dian = 0

char ch = " 0"; ; / * entrada + - * / */

char emp[80], suma[80], *e, *s;

doble = 0.000000000000;

p>

void init(void);

void clear _ z(char * u);

double strtoflt(char * p);

int getkey();

int gd=DETECT,GM;

init graph(&gd,&gm,"";

e = emp

s = suma;

init();

x = (obtener maxx()/2)-120; obtener maxy()/2)-150;

x 1 =(obtener maxx()/2)+120;

y 1 =(obtener maxy()/2 )+ 150;

mientras(1){

presionar = getkey();

Cambiar (presionar){

Extracto de caso:

Salir(0);

Caso 47:

barra (x + 10, y + 80 + 10, x + 60 - 10, y +8 60-10);

Retraso (8000);

init();

If (ch!='0'){

Cambiar(canal){

Caso "/":

if (strtoflt(emp)==0.0){

ch = "0";

ch_z = 0;

Dian = 0;

EMP[0]= '\0';

suma[0] = ' \ 0 ';

e = emp

s = suma;

outtextxy(x+30, y+40, "¡error! ! ! ! !");

Pausa;

}

Yuan = strtoflt(suma)/strtoflt(EMP);

sprintf(suma , " %0.10f ", yuanes);

clear _ z(suma

outtextxy(x+30, y+40, suma

Pausa;

Caso '*':

Elemento = strtoflt(suma)* strtoflt(EMP);

sprintf(suma, "%0.10f " , yuanes);

clear_z(suma);

outtextxy(x+30, y+40, suma);

Rotura;

outtextxy(x+30,y+40,sum);

Descanso;

p>

Caso "+":

Yuan= strtoflt(suma)+strtoflt(EMP);

sprintf(s

um, " %0.10f ", yuanes);

clear _ z(suma);

outtextxy(x+30, y+40, suma); p>Romper;

Caso '-':

if (strtoflt(sum)>=strtoflt(emp)){

Yuan = strtoflt(suma) -strtoflt(EMP);

sprintf(suma, " %0.10f ", yuanes

}

De lo contrario{

); Yuan = strtoflt(EMP)-strtoflt(suma);

sprintf(suma, "-%0.10f ", yuanes

}

clear _); z(suma);

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

}

}

De lo contrario{

if (ch_z==0){

outtextxy(x+30, y+40, EMP );

stpcpy(suma, EMP);

}

En caso contrario {

outtextxy(x+30, y+40, suma);

}

}

ch = '/';

ch _ z = 0;

EMP[0]= '\0';

e = emp

Dian = 0;

Rotura;

Caso 42:

barra (x + 60 + 10, y + 80 + 10, x + 60 * 2 - 10, y+860-10

Retraso (8000); );

init();

if (ch!='0'){

cambiar(canal){

Caso "/":

Yuan = strtoflt(suma)/strtoflt(EMP);

sprintf(suma, "%0.10f", Yuan);

clear_z(suma);

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

e = emp

Pausa;

Caso ' * ':

Elemento = strtoflt(suma)* strtoflt(EMP);

sprintf (suma, " %0.10f ", yuanes);

clear _ z(suma

outtextxy(x+30, y+40, suma);

EMP[0]= '\0';

e = emp

Romper;

Caso "+":

Yuan = strtoflt(suma)+strtoflt(EMP);

sprintf(suma, "%0.10f", yuanes);

clear _ z( suma);

outtextxy(x+30, y+40, suma);

EMP[0]= '\ 0';

e = emp

Pausa;

Caso '-':

if (strtoflt(sum)>=strtoflt(emp)){

Yuan = strtoflt(suma)- strtoflt(EMP);

sprintf(suma, " %0.10f ", yuanes

}

De lo contrario {

Yuan); = punto

rtoflt(EMP)-strtoflt(suma);

sprintf(suma, "-%0.10f ", yuanes);

}

clear _ z( suma);

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

e = emp

Pausa;

}

}

else{

if (ch_z==0){

outtextxy(x+30, y+40, EMP);

stpcpy(suma, EMP); }

Otros

outtextxy(x+30, y+40, suma);

}

ch = ' *

ch_z = 0;

Dian = 0;

Pausa;

Caso 45:

barra ( x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 - 10, y + 80 + 60-10);

Retraso (8000); );

if (ch!='0'){

cambiar(canal){

caso "/":

yuanes = strtoflt(suma)/strtoflt(EMP);

sprintf(suma, "%0.10f", yuanes);

clear_z(suma);

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

e = emp

Romper;

Caso '*':

Elemento = strtoflt(suma)* strtoflt(EMP);

sprintf(suma, " % 0.10f ", yuanes) ;

clear _ z(suma);

outtextxy(x+30, y+40, suma);

EMP[ 0]= '\0 ';

e = emp

Rotura;

Caso "+":

Yuan = strtoflt (suma)+strtoflt(EMP );

sprintf(suma, " %0.10f ", yuanes

clear _ z(suma

outtextxy(x+30,y); +40,suma);

EMP[0]= '\0';

e = emp

Rotura;

Caso '-':

if (strtoflt(sum)>=strtoflt(emp)){

Yuan= strtoflt(suma)-strtoflt(EMP

sprintf(suma, " %0.10f ", yuanes);

}

De lo contrario {

Yuan = strtoflt( EMP)-strtoflt(suma);

sprintf(suma, "-%0.10f ", yuanes

}

clear _ z(suma);

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

e = emp

e = emp

p>

Romper;

}

}

else{

if (ch_z= =0){

outtextxy(x+30,y+40,E

MP);

stpcpy(suma, EMP);

e = emp

}

Otros

outtextxy(x+30, y+40, suma);

}

ch = '-';

ch _ z = 0; >

Dian = 0;

Rotura;

Caso 43:

barra (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 - 10, y+860-10);

Retraso (8000);

init(); !='0'){

cambiar(canal){

case "/":

elemento = strtoflt(suma)/strtoflt(EMP);

sprintf(suma, " %0.10f ", yuanes);

clear _ z(suma);

outtextxy(x+30, y+ 40, suma);

EMP[0] = '\0';

e = emp

Pausa;

Caso ' * ' :

Yuan = strtoflt(suma)* strtoflt(EMP);

sprintf(suma, "%0.10f", Yuan);

clear_z(suma );

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

e = emp

Pausa;

Caso "+":

Yuan = strtoflt(suma)+strtoflt(EMP);

sprintf(suma, " %0.10f ", yuanes);

clear _ z(suma);

outtextxy(x+30, y+40, suma

EMP[0]= '\0';

e = emp

Romper;

Caso '-':

p>

if (strtoflt(suma)>=strtoflt(emp)){

Yuan= strtoflt(suma)-strtoflt(EMP);

sprintf(suma," %0.10 f ", yuan);

}

En caso contrario {

Yuan = strtoflt(EMP)-strtoflt(suma);

sprintf (suma, "-%0.10f ", yuanes);

}

clear _ z(suma

outtextxy(x+30, y+); 40, suma);

EMP[0]= '\0';

e = emp

Romper;

}

}

De lo contrario{

if (ch_z==0){

outtextxy(x+30, y+40, EMP) ;

stpcpy(suma, EMP);

e = emp

}

Otros

outtextxy( x+30, y+40, suma);

}

ch = '+';

ch _ z = 0

<; p>Dian = 0;

Ruptura;

Caso 49:

barra (x + 10, y + 80 + 53 + 10, x + 60 - 10, y+853 * 2-4);

Extensión

tiempo(8000);

init();

for(I = 0;i<=79;i++){

if (emp[i ]= ='\0 ')

Romper;

}

if (ch_z==0){

* e = ' 1 '; e++; * e = ' \ 0

outtextxy(x+30, y+40, EMP);

}

En caso contrario {

outtextxy(x+30, y+40, suma);

}

Descanso

Caso 50:

barra (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 - 10, y+853 * 2-4

Retraso (8000) ;

init();

for(I = 0;i<=79;i++){

if (emp[i]==' \0 ')

Romper;

}

if (ch_z==0){

* e = ' 2e++;* e = ' \ 0

outtextxy(x+30, y+40, EMP);

}

En caso contrario{

outtextxy (x+30, y+40, suma);

}

Descanso;

Caso 51:

barra (x + 60 * 2 + 10 , y + 80 + 53 + 10, x + 60 * 3 - 10, y + 80 + 53 * 2-4

Retraso (8000

init()); ;

for(I = 0;i<=79;i++){

if (emp[i]=='\0 ')

Romper;

}

if (ch_z==0){

* e = ' 3e++; * e = ' \ 0

outtextxy (x+30, y+40, EMP);

}

En caso contrario {

outtextxy(x+30, y+40,suma);

}

Pausa;

Entrada de caso:

bar (x + 60 * 3 + 10 , y + 80 + 53 + 10 , x + 60 * 4 - 10, y + 80 + 53 * 2-4

Retraso (8000);

init();

si (ch! ='0'){

Cambiar(canal){

Caso "/":

Yuan = strtoflt(sum)/strtoflt(EMP);

sprintf(suma, " %0.10f ", yuanes);

clear _ z(suma

outtextxy(x+30, y+40, suma);

EMP[0]= '\0';

e = emp

Romper;

Caso ' * ' :

Yuan = strtoflt(sum)* strtoflt(EMP);

sprintf(suma, "%0.10f", yuan);

clear _ z (suma);

outtextxy(x+30, y+40, suma);

EMP[0]= ' \ 0 ';

e = emp

Descanso;

Caso "+":

Yuan = strtoflt(suma)+strto

flt(EMP);

sprintf(suma, " %0.10f ", yuanes

clear _ z(suma

outtextxy(x+ 30); , y+40, suma);

EMP[0]= '\0';

e = emp

Descanso;

Caso '-':

if (strtoflt(sum)>=strtoflt(emp)){

Yuan = strtoflt(sum)-strtoflt(EMP);

p>

sprintf(suma, " %0.10f ", yuanes

}

De lo contrario {

yuan = strtoflt(EMP)-strtoflt); (suma);

sprintf(suma, "-%0.10f ", yuanes

}

clear _ z(suma); >

outtextxy(x+30, y+40, suma);

EMP[0]= '\0';

e = emp

Pausa;

}

}

else{

if (ch_z==0){

outtextxy(x+30, y+40, EMP);

stpcpy(suma, EMP

e = emp

}

<); p>En caso contrario{

outtextxy(x+30, y+40, suma);

}

}

ch = " 0";

ch_z = 1;

Dian = 0;

Rotura;

Caso 52:

barra (x + 10, y + 80 + 53 * 2 + 10, x + 60 - 10, y + 80 + 53 * 3-4

Retraso (8000);

init();

if (ch_z==0){

* e = ' 4e++; * e = ' \ 0

outtextxy( x+30, y+40, EMP);

}

En caso contrario {

outtextxy(x+30, y+40, suma);

}

Rotura;

Caso 53:

barra (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 - 10, y+853 * 3-4);

Retraso (8000);

init();

si (ch_z==0){

* e = ' 5e++; * e = ' \ 0

outtextxy(x+30, y+40, EMP

);

}

De lo contrario {

outtextxy(x+30, y+40, suma

}

Romper;

Caso 54:

barra (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 - 10, y +853 * 3-4);

Retraso (8000);

init();

if (ch_z==0){

* e = ' 6e++; * e = ' \ 0

outtextxy(x+30, y+40, EMP);

}

En caso contrario{

outtextxy(x+30, y+40, suma);

}

p>

Rotura;

Caso 46:

barra (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 - 10, y+853 * 3-4);

Retraso (8000

init();

if (dian==0); {

if (ch_z==0){

*e= ' . y+40, EMP);

}

En caso contrario {

outtextxy(x+30, y+40, suma);

}

}

En caso contrario{

if (ch_z==0)

outtextxy(x+30,y+ 40, EMP );

Otros

outtextxy(x+30, y+40, suma);

}

Dian = 1;

Pausa;

Caso 55:

barra (x + 10, y + 80 + 53 * 3 + 10, x + 60 - 10, y+80 +53 * 4-4);

Retraso (8000);

init();

if (ch_z==0){

* e = ' 7e++; * e = ' \ 0

outtextxy(x+30, y+40, EMP);

}

De lo contrario {

outtextxy(x+30, y+40, suma);

}

Descanso

Caso 56:

barra (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4-4); Retraso (8000);

init();

if (ch_z==0){

* e = ' 8e++;* e = ' \ 0

outtextxy(x+30, y+40, EMP);

}

En caso contrario{

outtextxy (x+30, y+40, suma);

}

Descanso;

Caso 57:

barra (x + 60 * 2 + 10 , y + 80 + 53 * 3 + 10, x + 60 * 3 - 10, y + 80 + 53 * 4-4

Retraso (8000); >init();

if (ch_z==0){

* e = ' 9e++; * e = ' \ 0

outtextxy(x+ 30, y+40, EMP);

}

De lo contrario {

outtextxy(x+30, y+40, suma

);

}

Rotura;

Caso 48:

barra (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 - 10, y+853 * 4-4);

Retraso (8000);

init();

si (ch_z==0){

* e = ' 0e++; * e = ' \ 0

outtextxy(x+30, y+40, EMP) ;

}

En caso contrario{

outtextxy(x+30, y+40, suma);

}

Rotura;

Caso 32:

EMP[0]= '\0';

suma[0]='\ 0 ';

e = emp

s = suma

ch = "0";

Dian = 0;

init();

Descanso

Caso 8:

Retraso ( 8000);

for(I = 0;i<=79;i++){

if (emp[i]=='\0 ')

Romper;

}

Si (i==0)

Romper;

Si (i! = 79 & amp& ampi! =0){

I-;

EMP[I]= '\0';

e = & ampEMP[I];

}

init();

outtextxy(x+30, y+40, EMP);

Romper;

p>

}

}

}

/* - */

void init(void){

int x, y, x1, y1, I, j;

char emp

x = (get maxx()/2)-120;

y =(obtener maxy()/2)-150;

x 1 =(obtener maxx()/2)+120;

y 1 =(obtener maxy ()/2)+150;

borrar dispositivo();

setbkcolor(3);

setfillstyle(1,15);

establecer color(15);

settextstyle(1, 0, 1);

Rectángulo (x, y, x1, y 1);

Rectangle(x - 7, y - 7, x1 + 7, y 1+7

Rectangle(x + 10, y + 10, x1 - 10, y+80-10);

Línea(x, y + 80, x1, y+80);

y = y+80

for(j = 1; j & lt = 4;j++){

x =(get maxx()/2)-120;

for(I = 1;i<= 4;i++){

/* barra (x + 10, y + 10, x + 60 - 10, y + 60-10 */

Rectángulo (x + 10, y + 10, x +); 60 - 10, y+60-10);

si (j == 1){

si (i == 1)

outtextxy( x + 20, y + 20, "/");

Si (i == 2)

outtextxy(x + 25, y + 20, "*"); p>

Si (i == 3)

outtextxy(x + 27, y + 20, "-");

Si (i == 4)

outtextxy(x + 25, y + 20, "+"

}

if (j == 2){

); si (i == 1)

outtextxy(x + 25, y + 20, " 1 "

Si (i == 2)

); outtextxy(x + 25, y + 20, " 2 ");

Si (i ==

3)

outtextxy(x + 25, y + 20, " 3 "

Si (i == 4)

outtextxy(x + 25); , y + 20, " = ");

}

si (j == 3){

si (i == 1)

outtextxy(x + 25, y + 20, " 4 ");

Si (i == 2)

outtextxy(x + 25, y + 20, " 5 ");

Si (i == 3)

outtextxy(x + 25, y + 20, " 6 "); i == 4)

outtextxy(x + 25, y + 20, " ");

}

if (j == 4){

si (i == 1)

outtextxy(x + 25, y + 20, " 7 ");

Si (i == 2)

outtextxy(x + 25, y + 20, " 8 ");

Si (i == 3)

outtextxy(x + 25, y +); 20, " 9 ");

Si (i == 4)

outtextxy(x + 25, y + 20, " 0 "); }

x = x+60;

}

y = y+53

}

}

/* - */

int getkey(){

char lowbyte

int press

while(tecla BIOS(1)== 0);

presione = tecla BIOS(0);

news=news&0xff? Prensa y Editoriales.

0x ff:presione>>8;

Retorno (presione);

}

doble strtoflt(char *p)

{

Doble RTL = 0.000000000000;

doble pnt = 0.000000000000

Doble t = 10;

int es punto = 0;

mientras (*p!='\0'||*p!='.'){

if(* p & lt; 0 ' | | * p & gt '9' )

Descanso;

RTL * = 10;

RTL+= * p-' 0 ';

p++; >

}

si (*p== ' . '){

es el punto = 1;

p++;

}

mientras(ispoint & amp;& amp*p!='\0'){

pnt+=(double)(* p-' 0 ') /t;

t * = 10;

p++;

}

RTL+= pnt; );

}

/* - */

void clear_z(char u[]){

int I ;

for(I = strlen(u)-1;i>=0;i-){

if (u[i]!='0')

Romper;

}

if (u[i]== ' . '){

u[I]= ' \ 0 ';

}

En caso contrario{

i++;

u[I]= '\ 0';

}

}