Calculatrice en C
Fermé
dr_melik
Messages postés
43
Date d'inscription
vendredi 18 janvier 2008
Statut
Membre
Dernière intervention
16 octobre 2009
-
27 janv. 2008 à 16:06
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 - 25 déc. 2011 à 20:18
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 - 25 déc. 2011 à 20:18
A voir également:
- Calculatrice en C
- Installer calculatrice sur mon portable - Télécharger - Calcul & Conversion
- Calculatrice gratuit - Télécharger - Calcul & Conversion
- Ma-calculatrice - Télécharger - Calcul & Conversion
- Calculatrice windows 7 - Télécharger - Calcul & Conversion
- Comment calculer la moyenne en excel - Guide
3 réponses
dr_melik
Messages postés
43
Date d'inscription
vendredi 18 janvier 2008
Statut
Membre
Dernière intervention
16 octobre 2009
6
27 janv. 2008 à 17:44
27 janv. 2008 à 17:44
svp je ve le programme d'un calculatrice en langage c
damlegone32
Messages postés
74
Date d'inscription
lundi 11 septembre 2006
Statut
Membre
Dernière intervention
31 mai 2011
29
27 janv. 2008 à 17:28
27 janv. 2008 à 17:28
ET????
#include"te.cpp"
HWND ht;
int restype,calc;
HWND button[50];
HWND edi,res;
HINSTANCE hinst;
char *tab[]={"7","8","9","/","Mod","asin","4","5","6","*","x","acos","1","2","3","-",
"Lsh","atan","0","+/-",",","+","=","sqrt","A","B","C","D","E","F",
"MC","MR","MS","M+","pi","F-E","(",")","dms","exp","ln","sin","x^y","log","cos",
"x^3","n!","tan","x^2","1/x"};
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wc;
HACCEL haccel;
hinst = hinstance;
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) 16;
wc.lpszMenuName = 0;
wc.lpszClassName = "Calculatrice";
if(!RegisterClass(&wc)) return FALSE;
hwnd = CreateWindow("Calculatrice","Calculatrice",
WS_CAPTION|WS_VISIBLE|WS_SYSMENU|WS_CLIPSIBLINGS|WS_OVERLAPPED|WS_MINIMIZEBOX|44,
CW_USEDEFAULT,CW_USEDEFAULT, 600,500,
NULL, NULL, hinstance, NULL);
if (!hwnd) return FALSE;
LoadLibrary("RICHED32.DLL");
ShowWindow(hwnd, 1);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{ case WM_CREATE:
int i,j,k,x,y;restype=1;calc=0;
char pp[50];
for(y=224,i=1,k=1;i<6;i++,y+=46)
for(j=1,x=321;j<7;k++,j++,x+=46)
{
button[k]=
CreateWindowEx(0,"button",tab[k-1],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,
x,y,36,29,hwnd,(HMENU)k,hinst,0);
}
for (i=0,y=224,x=245;i<5;i++,k++,y+=46)
button[k]=
CreateWindowEx(0,"button",tab[k-1],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,x,y,36,29,hwnd,(HMENU)k,hinst,0);
for(y=224,i=1;i<6;i++,y+=46)
for(j=1,x=72;j<4;k++,j++,x+=46)
button[k]=
CreateWindowEx(0,"button",tab[k-1],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,x,y,36,29,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Retour",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,318,180,100,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","CE",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,440,180,80,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","C",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,540,180,50,35,hwnd,(HMENU)k,hinst,0);
/*************************************************************************************/
button[k++]=
CreateWindowEx(0,"button",0,WS_CHILD|WS_VISIBLE|BS_GROUPBOX ,5,170,250,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Degrés",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON|WS_GROUP,10,180,70,20,hwnd,(HMENU)k,hinst,0);
SendMessage(button[k-1],BM_SETCHECK,1,0);
button[k++]=
CreateWindowEx(0,"button","Radians",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,90,180,70,20,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Grades",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,180,180,70,20,hwnd,(HMENU)k,hinst,0);
/*************************************************************************************/
button[k++]=
CreateWindowEx(0,"button",0,WS_CHILD|WS_VISIBLE|BS_GROUPBOX ,5,130,250,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Hex",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON|WS_GROUP,10,140,70,20,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Déc",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,90,140,70,20,hwnd,(HMENU)k,hinst,0);
SendMessage(button[k-1],BM_SETCHECK,1,0);
button[k++]=
CreateWindowEx(0,"button","Bin",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,180,140,70,20,hwnd,(HMENU)k,hinst,0);
edi=CreateWindowEx(0,"edit","",WS_CHILD|WS_VISIBLE |WS_TABSTOP|ES_MULTILINE|WS_HSCROLL|WS_BORDER|ES_AUTOHSCROLL,5,30,585,40,hwnd,(HMENU)100,hinst,0);
res=CreateWindowEx(0,"edit","0",WS_CHILD|WS_VISIBLE |ES_READONLY|WS_TABSTOP|WS_BORDER,5,80,585,20,hwnd,(HMENU)0,hinst,0);
/*************************************************************************************/
SetFocus(edi);
break;
case WM_COMMAND:
if(LOWORD(wParam)&&LOWORD(wParam)<63)
{
int i;SetFocus(edi);
for( i=0;i<nnum;i++)
if(num[i]==LOWORD(wParam))
{
ajout(&button[LOWORD(wParam)],&edi);break;}
if(i<nnum) break;
}
if(LOWORD(wParam)<63&& LOWORD(wParam)>59){restype=LOWORD(wParam)-60;calc=1;}
if(LOWORD(wParam)==43){ajout(0,&edi,"^");break;}
if(LOWORD(wParam)==46){ajout(0,&edi,"^3");break;}
if(LOWORD(wParam)==49){ajout(0,&edi,"^2");break;}
if(LOWORD(wParam)==50){ajout(0,&edi,"1/");break;}
if(calc||LOWORD(wParam)==23||
(LOWORD(wParam)==100&&HIWORD(wParam)==EN_CHANGE&&(GetKeyState(13)==-127||GetKeyState(13)==-128)))
{
char a2[200]="";calc=0;
GetWindowText(edi, a2,200);
for(i=0;a2[i];i++)
if(a2[i]==32){strcpy(a2+i,a2+i+1);--i;}
double re; char pp[100];
switch( calculer(a2,&re,0))
{
case 0:
switch(restype)
{
case 0:ltoa((long)re,pp,16);break;
case 1:sprintf(pp,"%lf",re);break;
case 2:ltoa((long)re,pp,2);break;
}break;
case 1: sprintf(pp,"Erreur"); break;
case 2:sprintf(pp,"Resultat graphic"); break;
}
SetWindowText(res,pp);
SetFocus(edi);
}
if(LOWORD(wParam)==52) SendMessage(edi, WM_UNDO, 0, 0);
if(LOWORD(wParam)==53|| LOWORD(wParam)==54)SetWindowText(edi,"");
break;
case WM_KEYDOWN:
SetFocus(edi);break;
case WM_DESTROY:
case WM_CLOSE:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
HWND ht;
int restype,calc;
HWND button[50];
HWND edi,res;
HINSTANCE hinst;
char *tab[]={"7","8","9","/","Mod","asin","4","5","6","*","x","acos","1","2","3","-",
"Lsh","atan","0","+/-",",","+","=","sqrt","A","B","C","D","E","F",
"MC","MR","MS","M+","pi","F-E","(",")","dms","exp","ln","sin","x^y","log","cos",
"x^3","n!","tan","x^2","1/x"};
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wc;
HACCEL haccel;
hinst = hinstance;
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) 16;
wc.lpszMenuName = 0;
wc.lpszClassName = "Calculatrice";
if(!RegisterClass(&wc)) return FALSE;
hwnd = CreateWindow("Calculatrice","Calculatrice",
WS_CAPTION|WS_VISIBLE|WS_SYSMENU|WS_CLIPSIBLINGS|WS_OVERLAPPED|WS_MINIMIZEBOX|44,
CW_USEDEFAULT,CW_USEDEFAULT, 600,500,
NULL, NULL, hinstance, NULL);
if (!hwnd) return FALSE;
LoadLibrary("RICHED32.DLL");
ShowWindow(hwnd, 1);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{ case WM_CREATE:
int i,j,k,x,y;restype=1;calc=0;
char pp[50];
for(y=224,i=1,k=1;i<6;i++,y+=46)
for(j=1,x=321;j<7;k++,j++,x+=46)
{
button[k]=
CreateWindowEx(0,"button",tab[k-1],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,
x,y,36,29,hwnd,(HMENU)k,hinst,0);
}
for (i=0,y=224,x=245;i<5;i++,k++,y+=46)
button[k]=
CreateWindowEx(0,"button",tab[k-1],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,x,y,36,29,hwnd,(HMENU)k,hinst,0);
for(y=224,i=1;i<6;i++,y+=46)
for(j=1,x=72;j<4;k++,j++,x+=46)
button[k]=
CreateWindowEx(0,"button",tab[k-1],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,x,y,36,29,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Retour",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,318,180,100,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","CE",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,440,180,80,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","C",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,540,180,50,35,hwnd,(HMENU)k,hinst,0);
/*************************************************************************************/
button[k++]=
CreateWindowEx(0,"button",0,WS_CHILD|WS_VISIBLE|BS_GROUPBOX ,5,170,250,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Degrés",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON|WS_GROUP,10,180,70,20,hwnd,(HMENU)k,hinst,0);
SendMessage(button[k-1],BM_SETCHECK,1,0);
button[k++]=
CreateWindowEx(0,"button","Radians",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,90,180,70,20,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Grades",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,180,180,70,20,hwnd,(HMENU)k,hinst,0);
/*************************************************************************************/
button[k++]=
CreateWindowEx(0,"button",0,WS_CHILD|WS_VISIBLE|BS_GROUPBOX ,5,130,250,35,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Hex",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON|WS_GROUP,10,140,70,20,hwnd,(HMENU)k,hinst,0);
button[k++]=
CreateWindowEx(0,"button","Déc",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,90,140,70,20,hwnd,(HMENU)k,hinst,0);
SendMessage(button[k-1],BM_SETCHECK,1,0);
button[k++]=
CreateWindowEx(0,"button","Bin",WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,180,140,70,20,hwnd,(HMENU)k,hinst,0);
edi=CreateWindowEx(0,"edit","",WS_CHILD|WS_VISIBLE |WS_TABSTOP|ES_MULTILINE|WS_HSCROLL|WS_BORDER|ES_AUTOHSCROLL,5,30,585,40,hwnd,(HMENU)100,hinst,0);
res=CreateWindowEx(0,"edit","0",WS_CHILD|WS_VISIBLE |ES_READONLY|WS_TABSTOP|WS_BORDER,5,80,585,20,hwnd,(HMENU)0,hinst,0);
/*************************************************************************************/
SetFocus(edi);
break;
case WM_COMMAND:
if(LOWORD(wParam)&&LOWORD(wParam)<63)
{
int i;SetFocus(edi);
for( i=0;i<nnum;i++)
if(num[i]==LOWORD(wParam))
{
ajout(&button[LOWORD(wParam)],&edi);break;}
if(i<nnum) break;
}
if(LOWORD(wParam)<63&& LOWORD(wParam)>59){restype=LOWORD(wParam)-60;calc=1;}
if(LOWORD(wParam)==43){ajout(0,&edi,"^");break;}
if(LOWORD(wParam)==46){ajout(0,&edi,"^3");break;}
if(LOWORD(wParam)==49){ajout(0,&edi,"^2");break;}
if(LOWORD(wParam)==50){ajout(0,&edi,"1/");break;}
if(calc||LOWORD(wParam)==23||
(LOWORD(wParam)==100&&HIWORD(wParam)==EN_CHANGE&&(GetKeyState(13)==-127||GetKeyState(13)==-128)))
{
char a2[200]="";calc=0;
GetWindowText(edi, a2,200);
for(i=0;a2[i];i++)
if(a2[i]==32){strcpy(a2+i,a2+i+1);--i;}
double re; char pp[100];
switch( calculer(a2,&re,0))
{
case 0:
switch(restype)
{
case 0:ltoa((long)re,pp,16);break;
case 1:sprintf(pp,"%lf",re);break;
case 2:ltoa((long)re,pp,2);break;
}break;
case 1: sprintf(pp,"Erreur"); break;
case 2:sprintf(pp,"Resultat graphic"); break;
}
SetWindowText(res,pp);
SetFocus(edi);
}
if(LOWORD(wParam)==52) SendMessage(edi, WM_UNDO, 0, 0);
if(LOWORD(wParam)==53|| LOWORD(wParam)==54)SetWindowText(edi,"");
break;
case WM_KEYDOWN:
SetFocus(edi);break;
case WM_DESTROY:
case WM_CLOSE:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
associe tou ces codes
#include <conio.h>
#include <shlobj.h>
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<float.h>
#include<windows.h>
#include<windowsx.h>
#include <richedit.h>
#include"stdlib.h"
HWND hwnd;
CHARRANGE sel;
int atofa(char *,double *,int *,double);
int calkilez(char *,double *,int *,double);
int calculer(char *,double*,double var=0);
char *add(char *a,float b)
{
int k;int i=0;float c;int neg=0;
if(b<0)
{neg=1;b*=-1;}
k=(int)b;
while(k>0)
{
a[i++]=k%10+48;k/=10;
}
k=(int)b;
c=b-k;
if(neg)a[i++]='-';
a[i]=0;
strrev(a);
k=i=strlen(a);
a[i++]='.';
do
{
c*=10;
a[i++]=(int)c+48;
c=c-(int)c;
}while(c>0&&i<(k+3));
a[i]=0;
return a;
}
int chang(char *p,char *a,char *b)
{
int la=strlen(a);
char *m;
char *tmp=(char*)malloc(strlen(p));
int x=0;
for(m=p;*m;m++)
if(!strncmp(m,a,la)&&(x=1))
strcpy(m,m+la)&&strcpy(tmp,b)&&strcat(tmp,m)&&strcpy(m,tmp);
return x;
}
int atofa(char *p,double *x,int *erreur,double var)
{
char *i=p, signe=1;
if(*p=='+'||*p=='-')
{
if(*p=='-')signe=-1;
++p;
}
if(*p=='s'||*p=='c'||*p=='t'||*p=='l'||*p=='e'||*p=='r'||*p=='p'||*p=='m'
||*p=='x'||*p=='d'||*p=='b'||*p=='f')
{
char type=*p;
if(*p!='p'&&*p!='x')
{++p;p+=(*(p)=='(')?calkilez(p+1,x,erreur,var)+1:atofa(p,x,erreur,var);}
switch(type)
{
case 's':*x=sin(*x);break;
case 'm':if(*x<=0)*erreur=1;else*x=log10(*x);break;
case 'c':*x=cos(*x);break;
case 'f':*x=acos(*x);break;
case 'b':*x=asin(*x);break;
case 'd':*x=atan(*x);break;
case 't':*x=tan(*x);break;
case 'l':if(*x<=0)*erreur=1;else*x=log(*x);break;
case 'e':*x=exp(*x);break;
case 'r':if(*x<0)*erreur=1;else *x=sqrt(*x);break;
case 'p':++p;*x=3.1415926535897932384626433832795;break;
case 'x':++p;*x=var;break;
}
if(*x<=0.00000000000001&&*x>=-0.00000000000001)*x=0;
}
else
{char *t,op;double a3;
if(*p=='(')p+=calkilez(p+1,x,erreur,var)+1;
else
{ *x=atof(p); while(isdigit(*p)||*p=='.')++p;}
do
{ t=p;
op=*p++;
if(op=='a'){
p+=(*p=='(')?calkilez(p+1,&a3,erreur,var)+1:atofa(p,&a3,erreur,var);
//if(a3<0)*erreur=1;else
*x=pow(*x,a3);
}else p=t;
}while(p!=t);
}
*x*=signe;
return p-i;
}
int calkilez(char *p,double *resultat,int *erreur,double var)
{char *i=p;char *t;
double a1=0,a2,a3,a4;int op1,op2,op3;
op1=(*p=='-')?*p++:'+';
p+=(*p=='(')?calkilez(p+1,&a2,erreur,var)+1:atofa(p,&a2,erreur,var);
while(*p!=')'&&*p)
{
op2=*p++;
p+=(*p=='(')?calkilez(p+1,&a3,erreur,var)+1:atofa(p,&a3,erreur,var);
if(op2=='a')if(a2<0&&(a3!=(int)a3))*erreur=1;else a2=pow(a2,a3);
else
if(op2=='*'||op2=='/')
{
do
{ t=p;
op3=*p++;
if(op3=='a'){
p+=(*p=='(')?calkilez(p+1,&a4,erreur,var)+1:atofa(p,&a4,erreur,var);
if(a3<0)*erreur=1;else a3=pow(a3,a4);
}else p=t;
}while(p!=t);
if(op2=='*')a2*=a3;
else if(a3==0)*erreur=1;
else a2/=a3;
}
else
{
a1+=(op1=='+')?a2:-a2;
a2=a3;
op1=op2;
}
}
if(op1=='+')a1+=a2; else a1-=a2;
*resultat=a1;
return (p-i)+1;
}
int calculer(char *m ,double *resultat,double var)
{
int erreur=0;
while(chang(m,"++","+")|| chang(m,"--","+")|| chang(m,"+-","-")||
chang(m,"--","+")||chang(m,"-+","-"));
while(chang(m,"asin","f"));
while(chang(m,"acos","b"));
while(chang(m,"atan","d"));
while(chang(m,"sin","s"));
while(chang(m,"cos","c"));
while(chang(m,"tan","t"));
while(chang(m,"pi","p"));
while(chang(m,"log","m"));
while(chang(m,"ln","l"));
while(chang(m,"exp","e"));
while(chang(m,"sqrt","r"));
while(chang(m,"^","a"));
if(chang(m,"x","x")||chang(m,"X","x"))
{erreur=2;
ShellExecute( hwnd, NULL,"graph",m, NULL,1);
}
else
calkilez(m,resultat,&erreur,var);
return erreur;
}
#include <conio.h>
#include <shlobj.h>
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<float.h>
#include<windows.h>
#include<windowsx.h>
#include <richedit.h>
#include"stdlib.h"
HWND hwnd;
CHARRANGE sel;
int atofa(char *,double *,int *,double);
int calkilez(char *,double *,int *,double);
int calculer(char *,double*,double var=0);
char *add(char *a,float b)
{
int k;int i=0;float c;int neg=0;
if(b<0)
{neg=1;b*=-1;}
k=(int)b;
while(k>0)
{
a[i++]=k%10+48;k/=10;
}
k=(int)b;
c=b-k;
if(neg)a[i++]='-';
a[i]=0;
strrev(a);
k=i=strlen(a);
a[i++]='.';
do
{
c*=10;
a[i++]=(int)c+48;
c=c-(int)c;
}while(c>0&&i<(k+3));
a[i]=0;
return a;
}
int chang(char *p,char *a,char *b)
{
int la=strlen(a);
char *m;
char *tmp=(char*)malloc(strlen(p));
int x=0;
for(m=p;*m;m++)
if(!strncmp(m,a,la)&&(x=1))
strcpy(m,m+la)&&strcpy(tmp,b)&&strcat(tmp,m)&&strcpy(m,tmp);
return x;
}
int atofa(char *p,double *x,int *erreur,double var)
{
char *i=p, signe=1;
if(*p=='+'||*p=='-')
{
if(*p=='-')signe=-1;
++p;
}
if(*p=='s'||*p=='c'||*p=='t'||*p=='l'||*p=='e'||*p=='r'||*p=='p'||*p=='m'
||*p=='x'||*p=='d'||*p=='b'||*p=='f')
{
char type=*p;
if(*p!='p'&&*p!='x')
{++p;p+=(*(p)=='(')?calkilez(p+1,x,erreur,var)+1:atofa(p,x,erreur,var);}
switch(type)
{
case 's':*x=sin(*x);break;
case 'm':if(*x<=0)*erreur=1;else*x=log10(*x);break;
case 'c':*x=cos(*x);break;
case 'f':*x=acos(*x);break;
case 'b':*x=asin(*x);break;
case 'd':*x=atan(*x);break;
case 't':*x=tan(*x);break;
case 'l':if(*x<=0)*erreur=1;else*x=log(*x);break;
case 'e':*x=exp(*x);break;
case 'r':if(*x<0)*erreur=1;else *x=sqrt(*x);break;
case 'p':++p;*x=3.1415926535897932384626433832795;break;
case 'x':++p;*x=var;break;
}
if(*x<=0.00000000000001&&*x>=-0.00000000000001)*x=0;
}
else
{char *t,op;double a3;
if(*p=='(')p+=calkilez(p+1,x,erreur,var)+1;
else
{ *x=atof(p); while(isdigit(*p)||*p=='.')++p;}
do
{ t=p;
op=*p++;
if(op=='a'){
p+=(*p=='(')?calkilez(p+1,&a3,erreur,var)+1:atofa(p,&a3,erreur,var);
//if(a3<0)*erreur=1;else
*x=pow(*x,a3);
}else p=t;
}while(p!=t);
}
*x*=signe;
return p-i;
}
int calkilez(char *p,double *resultat,int *erreur,double var)
{char *i=p;char *t;
double a1=0,a2,a3,a4;int op1,op2,op3;
op1=(*p=='-')?*p++:'+';
p+=(*p=='(')?calkilez(p+1,&a2,erreur,var)+1:atofa(p,&a2,erreur,var);
while(*p!=')'&&*p)
{
op2=*p++;
p+=(*p=='(')?calkilez(p+1,&a3,erreur,var)+1:atofa(p,&a3,erreur,var);
if(op2=='a')if(a2<0&&(a3!=(int)a3))*erreur=1;else a2=pow(a2,a3);
else
if(op2=='*'||op2=='/')
{
do
{ t=p;
op3=*p++;
if(op3=='a'){
p+=(*p=='(')?calkilez(p+1,&a4,erreur,var)+1:atofa(p,&a4,erreur,var);
if(a3<0)*erreur=1;else a3=pow(a3,a4);
}else p=t;
}while(p!=t);
if(op2=='*')a2*=a3;
else if(a3==0)*erreur=1;
else a2/=a3;
}
else
{
a1+=(op1=='+')?a2:-a2;
a2=a3;
op1=op2;
}
}
if(op1=='+')a1+=a2; else a1-=a2;
*resultat=a1;
return (p-i)+1;
}
int calculer(char *m ,double *resultat,double var)
{
int erreur=0;
while(chang(m,"++","+")|| chang(m,"--","+")|| chang(m,"+-","-")||
chang(m,"--","+")||chang(m,"-+","-"));
while(chang(m,"asin","f"));
while(chang(m,"acos","b"));
while(chang(m,"atan","d"));
while(chang(m,"sin","s"));
while(chang(m,"cos","c"));
while(chang(m,"tan","t"));
while(chang(m,"pi","p"));
while(chang(m,"log","m"));
while(chang(m,"ln","l"));
while(chang(m,"exp","e"));
while(chang(m,"sqrt","r"));
while(chang(m,"^","a"));
if(chang(m,"x","x")||chang(m,"X","x"))
{erreur=2;
ShellExecute( hwnd, NULL,"graph",m, NULL,1);
}
else
calkilez(m,resultat,&erreur,var);
return erreur;
}
#include"h.cpp"
int num[40]={1,2,3,4,7,8,9,10,13,14,15,16,19,21,22,37,38,40,41,42,44,45,48,35
,21,6,12,18,24,11}
,nnum=39;
void ajout(HWND *a,HWND *b,char *ppa=0)
{
char pp[20];
if(!ppa)
GetWindowText(*a, pp,20);
else sprintf(pp,"%s",ppa);
SendMessage(*b, EM_EXGETSEL, 0, (LPARAM) &sel);
SendMessage(*b, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR) pp);
SetFocus(*b);
}
int num[40]={1,2,3,4,7,8,9,10,13,14,15,16,19,21,22,37,38,40,41,42,44,45,48,35
,21,6,12,18,24,11}
,nnum=39;
void ajout(HWND *a,HWND *b,char *ppa=0)
{
char pp[20];
if(!ppa)
GetWindowText(*a, pp,20);
else sprintf(pp,"%s",ppa);
SendMessage(*b, EM_EXGETSEL, 0, (LPARAM) &sel);
SendMessage(*b, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR) pp);
SetFocus(*b);
}
voila un exemple
fiddy
Messages postés
11069
Date d'inscription
samedi 5 mai 2007
Statut
Contributeur
Dernière intervention
23 avril 2022
1 844
22 déc. 2011 à 21:43
22 déc. 2011 à 21:43
Vous répondez à un post datant de 2008.
En plus, vous mettez du C++ alors que la question était en C. Et enfin, inclure un .cpp dans un code, c'est une très mauvaise pratique.
En plus, vous mettez du C++ alors que la question était en C. Et enfin, inclure un .cpp dans un code, c'est une très mauvaise pratique.
fiddy
Messages postés
11069
Date d'inscription
samedi 5 mai 2007
Statut
Contributeur
Dernière intervention
23 avril 2022
1 844
25 déc. 2011 à 20:18
25 déc. 2011 à 20:18
#include"h.cpp"
.cpp c'est du C++...
.cpp c'est du C++...