c語言中數(shù)學(xué)庫函數(shù)計(jì)算器 c語言的計(jì)算器

如何用c語言實(shí)現(xiàn)一個(gè)計(jì)算器???

1、#includestdio.hint?main()

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、大姚網(wǎng)站維護(hù)、網(wǎng)站推廣。

2、{????int?a,b,c;????scanf("%d%d%d",a,b,c);

3、?int?sum?=?a+b+c;

4、???printf("和:?%d",sum);

5、printf("平均值:%f",sum/3.0);

6、return?0

講解:

1、先定義四個(gè)整形。

2、一個(gè)浮點(diǎn)型保存平均值。

3、然后在控制臺(tái)等待輸入。

4、將輸入的三個(gè)整數(shù)加起來賦值給sum。

5、將三個(gè)整形除以3.0(為什么是3.0,是因?yàn)閍ve是浮點(diǎn)型的,隱性轉(zhuǎn)換到float)。

6、然后輸出。

用c語言 (c++) 編寫計(jì)算器程序

我們平時(shí)進(jìn)行數(shù)學(xué)運(yùn)算都是用計(jì)算器完成的,那么如何用C語言編寫一個(gè)計(jì)算器呢?下面我給大家分享一下。

工具/材料

Dev C++

01

首先我們需要在Dev C++軟件中創(chuàng)建一個(gè)C語言項(xiàng)目,項(xiàng)目類型選擇控制臺(tái)程序,如下圖所示

02

接下來我們在項(xiàng)目下面新建C語言文件,如下圖所示

03

然后我們在C文件中寫入計(jì)算器邏輯代碼,主要是讓用戶輸入計(jì)算方式,然后程序自動(dòng)計(jì)算,如下圖所示

04

接下來我們點(diǎn)擊運(yùn)行菜單,選擇下拉菜單中的運(yùn)行選項(xiàng),如下圖所示

05

最后在彈出的界面中我們輸入要計(jì)算的公式,程序就會(huì)自動(dòng)計(jì)算,如下圖所示

C語言計(jì)算器程序

請仔細(xì)看輸入方法,別輸錯(cuò)了,要不然答案不正確的[原創(chuàng)]函數(shù)型計(jì)算器(VC++6.0,win32 console)/*---------------------------------------

函數(shù)型計(jì)算器(VC++6.0,Win32 Console)

程序由 yu_hua 于2007-07-27設(shè)計(jì)完成

功能:目前提供了10多個(gè)常用數(shù)學(xué)函數(shù):

⑴正弦sin ⑵余弦cos ⑶正切tan

⑷開平方sqrt ⑸反正弦arcsin

⑹反余弦arccos ⑺反正切arctan

⑻常用對數(shù)lg ⑼自然對數(shù)ln

⑽e指數(shù)exp ⑾乘冪函數(shù)∧

用法:如果要求2的32次冪,可以打入

2^32回車如果要求30度角的正切可

鍵入tan(Pi/6)回車注意不能打入:

tan(30)Enter如果要求1.23弧度的

正弦,有幾種方法都有效:

sin(1.23)Enter

sin 1.23 Enter

sin1.23 Enter

如果驗(yàn)證正余弦的平方和公式,可打入

sin(1.23)^2+cos(1.23)^2 Enter或

sin1.23^2+cos1.23^2 Enter此外兩

函數(shù)表達(dá)式連在一起,自動(dòng)理解為相乘

如:sin1.23cos0.77+cos1.23sin0.77

就等價(jià)于

sin(1.23)*cos(0.77)+cos(1.23)*sin(0.77)

當(dāng)然你還可以依據(jù)三角變換,再用

sin(1.23+0.77)也即sin2驗(yàn)證一下。

本計(jì)算器充分考慮了運(yùn)算符的優(yōu)先級

因此諸如:2+3*4^2 實(shí)際上相當(dāng)于:

2+(3*(4*4))另外函數(shù)名前面如果是

數(shù)字,那么自動(dòng)認(rèn)為二者相乘.同理,

如果某數(shù)的右側(cè)是左括號,則自動(dòng)

認(rèn)為該數(shù)與括弧項(xiàng)之間隱含一乘號。

如:3sin1.2^2+5cos2.1^2 相當(dāng)于

3*sin2(1.2)+5*cos2(2.1) 又如:

4(3-2(sqrt5-1)+ln2)+lg5 相當(dāng)于

4*(3-2*(√5 -1)+loge(2))+log10(5)

此外,本計(jì)算器提供了圓周率 Pi

鍵入字母時(shí)不區(qū)分大小寫,以方便使用。

----------------------------------------*/

#include iostream

#include iomanip

#include cstdlib

#include cstring

#include cctype

#include cmath

using namespace std;const char Tab=0x9;

const int DIGIT=1;double fun(double x,char op[],int *iop)

{

while(op[*iop-1]32) //本行使得函數(shù)嵌套調(diào)用時(shí)不必加括號

// 如 arc sin(sin(1.234)) 只需鍵入arc sin sin 1.234Enter

switch(op[*iop-1])

{

case 7: x=sin(x); (*iop)--;break;

case 8: x=cos(x); (*iop)--;break;

case 9: x=tan(x); (*iop)--;break;

case 10: x=sqrt(x); (*iop)--;break;

case 11: x=asin(x); (*iop)--;break;

case 12: x=acos(x); (*iop)--;break;

case 13: x=atan(x); (*iop)--;break;

case 14: x=log10(x);(*iop)--;break;

case 15: x=log(x); (*iop)--;break;

case 16: x=exp(x); (*iop)--;break;

}

return x;

}double calc(char *expr,char **addr)

{

static deep; //遞歸深度

static char *fname[]={ "sin","cos","tan","sqrt",

"arcsin","arccos","arctan","lg","ln","exp",NULL};

double ST[10]={0.0}; //數(shù)字棧

char op[10]={'+'}; //運(yùn)算符棧

char c,*rexp,*pp,*pf;

int ist=1,iop=1,last;

if(!deep)

{

pp=pf=expr;

do

{

c = *pp++;

if(c!=' ' c!=Tab)

*pf++ = c;

}

while(c!='\0');

}

pp=expr;

if((c=*pp)=='-'||c=='+')

{

op[0] = c;

pp++;

}

last = !DIGIT;

while((c=*pp)!='\0')

{

if(c=='(')//左圓括弧

{

deep++;

ST[ist++]=calc(++pp,addr);

deep--;

ST[ist-1]=fun(ST[ist-1],op,iop);

pp = *addr;

last = DIGIT;

if(*pp == '('||isalpha(*pp) strnicmp(pp,"Pi",2))

{ ////目的是:當(dāng)右圓括弧的

op[iop++]='*'; ////右惻為左圓括弧或函數(shù)

last = !DIGIT; ////名字時(shí),默認(rèn)其為乘法

c = op[--iop]; /////////////////////////////

goto operate ; /////////////////////////////

}

}

else if(c==')')//右圓括弧

{

pp++;

break;

}

else if(isalpha(c))

{

if(!strnicmp(pp,"Pi",2))

{

if(last==DIGIT){cout "π左側(cè)遇)" endl;exit(1);}

ST[ist++]=3.14159265358979323846;

ST[ist-1]=fun(ST[ist-1],op,iop);

pp += 2;

last = DIGIT;

if(!strnicmp(pp,"Pi",2)){cout "兩個(gè)π相連" endl;exit(2);}

if(*pp=='('){cout "π右側(cè)遇(" endl;exit(3);}

}

else

{

for(int i=0; (pf=fname[i])!=NULL; i++)

if(!strnicmp(pp,pf,strlen(pf)))break;

if(pf!=NULL)

{

op[iop++] = 07+i;

pp += strlen(pf);

}

else {cout "陌生函數(shù)名" endl;exit(4);}

}

}

else if(c=='+'||c=='-'||c=='*'||c=='/'||c=='^')

{

char cc;

if(last != DIGIT){cout "運(yùn)算符粘連" endl;exit(5);}

pp++;

if(c=='+'||c=='-')

{

do

{

cc = op[--iop];

--ist;

switch(cc)

{

case '+': ST[ist-1] += ST[ist];break;

case '-': ST[ist-1] -= ST[ist];break;

case '*': ST[ist-1] *= ST[ist];break;

case '/': ST[ist-1] /= ST[ist];break;

case '^': ST[ist-1] = pow(ST[ist-1],ST[ist]);break;

}

}

while(iop);

op[iop++] = c;

}

else if(c=='*'||c=='/')

{

operate: cc = op[iop-1];

if(cc=='+'||cc=='-')

{

op[iop++] = c;

}

else

{

--ist;

op[iop-1] = c;

switch(cc)

{

case '*': ST[ist-1] *= ST[ist];break;

case '/': ST[ist-1] /= ST[ist];break;

case '^': ST[ist-1] = pow(ST[ist-1],ST[ist]);break;

}

}

}

else

{

cc = op[iop-1];

if(cc=='^'){cout "乘冪符連用" endl;exit(6);}

op[iop++] = c;

}

last = !DIGIT;

}

else

{

if(last == DIGIT){cout "兩數(shù)字粘連" endl;exit(7);}

ST[ist++]=strtod(pp,rexp);

ST[ist-1]=fun(ST[ist-1],op,iop);

if(pp == rexp){cout "非法字符" endl;exit(8);}

pp = rexp;

last = DIGIT;

if(*pp == '('||isalpha(*pp))

{

op[iop++]='*';

last = !DIGIT;

c = op[--iop]; /////////////////////////////

goto operate ; /////////////////////////////

}

}

}

*addr=pp;

if(iop=ist){cout "表達(dá)式有誤" endl;exit(9);}

while(iop)

{

--ist;

switch(op[--iop])

{

case '+': ST[ist-1] += ST[ist];break;

case '-': ST[ist-1] -= ST[ist];break;

case '*': ST[ist-1] *= ST[ist];break;

case '/': ST[ist-1] /= ST[ist];break;

case '^': ST[ist-1] = pow(ST[ist-1],ST[ist]);break;

}

}

return ST[0];

}int main()

{

char s[128],*end;

system("chcp 936"); //中文代碼頁

while(1)

{

cout "請輸入表達(dá)式:";

cin.getline(s,128);

cout setprecision(17) calc(s,end) endl;

}

return 0;

C語言計(jì)算器

!!你不寫上,我怎么幫你,計(jì)算器程序我這也有一個(gè) ,看看不

include dos.h /*DOS接口函數(shù)*/

#include math.h /*數(shù)學(xué)函數(shù)的定義*/

#include conio.h /*屏幕操作函數(shù)*/

#include stdio.h /*I/O函數(shù)*/

#include stdlib.h /*庫函數(shù)*/

#include stdarg.h /*變量長度參數(shù)表*/

#include graphics.h /*圖形函數(shù)*/

#include string.h /*字符串函數(shù)*/

#include ctype.h /*字符操作函數(shù)*/

#define UP 0x48 /*光標(biāo)上移鍵*/

#define DOWN 0x50 /*光標(biāo)下移鍵*/

#define LEFT 0x4b /*光標(biāo)左移鍵*/

#define RIGHT 0x4d /*光標(biāo)右移鍵*/

#define ENTER 0x0d /*回車鍵*/

void *rar; /*全局變量,保存光標(biāo)圖象*/

struct palettetype palette; /*使用調(diào)色板信息*/

int GraphDriver; /* 圖形設(shè)備驅(qū)動(dòng)*/

int GraphMode; /* 圖形模式值*/

int ErrorCode; /* 錯(cuò)誤代碼*/

int MaxColors; /* 可用顏色的最大數(shù)值*/

int MaxX, MaxY; /* 屏幕的最大分辨率*/

double AspectRatio; /* 屏幕的像素比*/

void drawboder(void); /*畫邊框函數(shù)*/

void initialize(void); /*初始化函數(shù)*/

void computer(void); /*計(jì)算器計(jì)算函數(shù)*/

void changetextstyle(int font, int direction, int charsize); /*改變文本樣式函數(shù)*/

void mwindow(char *header); /*窗口函數(shù)*/

int specialkey(void) ; /*獲取特殊鍵函數(shù)*/

int arrow(); /*設(shè)置箭頭光標(biāo)函數(shù)*/

/*主函數(shù)*/

int main()

{

initialize();/* 設(shè)置系統(tǒng)進(jìn)入圖形模式 */

computer(); /*運(yùn)行計(jì)算器 */

closegraph();/*系統(tǒng)關(guān)閉圖形模式返回文本模式*/

return(0); /*結(jié)束程序*/

}

/* 設(shè)置系統(tǒng)進(jìn)入圖形模式 */

void initialize(void)

{

int xasp, yasp; /* 用于讀x和y方向縱橫比*/

GraphDriver = DETECT; /* 自動(dòng)檢測顯示器*/

initgraph( GraphDriver, GraphMode, "" );

/*初始化圖形系統(tǒng)*/

ErrorCode = graphresult(); /*讀初始化結(jié)果*/

if( ErrorCode != grOk ) /*如果初始化時(shí)出現(xiàn)錯(cuò)誤*/

{

printf("Graphics System Error: %s\n",

grapherrormsg( ErrorCode ) ); /*顯示錯(cuò)誤代碼*/

exit( 1 ); /*退出*/

}

getpalette( palette ); /* 讀面板信息*/

MaxColors = getmaxcolor() + 1; /* 讀取顏色的最大值*/

MaxX = getmaxx(); /* 讀屏幕尺寸 */

MaxY = getmaxy(); /* 讀屏幕尺寸 */

getaspectratio( xasp, yasp ); /* 拷貝縱橫比到變量中*/

AspectRatio = (double)xasp/(double)yasp;/* 計(jì)算縱橫比值*/

}

/*計(jì)算器函數(shù)*/

void computer(void)

{

struct viewporttype vp; /*定義視口類型變量*/

int color, height, width;

int x, y,x0,y0, i, j,v,m,n,act,flag=1;

float num1=0,num2=0,result; /*操作數(shù)和計(jì)算結(jié)果變量*/

char cnum[5],str2[20]={""},c,temp[20]={""};

char str1[]="1230.456+-789*/Qc=^%";/* 定義字符串在按鈕圖形上顯示的符號 */

mwindow( "Calculator" ); /* 顯示主窗口 */

color = 7; /*設(shè)置灰顏色值*/

getviewsettings( vp ); /* 讀取當(dāng)前窗口的大小*/

width=(vp.right+1)/10; /* 設(shè)置按鈕寬度 */

height=(vp.bottom-10)/10 ; /*設(shè)置按鈕高度 */

x = width /2; /*設(shè)置x的坐標(biāo)值*/

y = height/2; /*設(shè)置y的坐標(biāo)值*/

setfillstyle(SOLID_FILL, color+3);

bar( x+width*2, y, x+7*width, y+height );

/*畫一個(gè)二維矩形條顯示運(yùn)算數(shù)和結(jié)果*/

setcolor( color+3 ); /*設(shè)置淡綠顏色邊框線*/

rectangle( x+width*2, y, x+7*width, y+height );

/*畫一個(gè)矩形邊框線*/

setcolor(RED); /*設(shè)置顏色為紅色*/

outtextxy(x+3*width,y+height/2,"0."); /*輸出字符串"0."*/

x =2*width-width/2; /*設(shè)置x的坐標(biāo)值*/

y =2*height+height/2; /*設(shè)置y的坐標(biāo)值*/

for( j=0 ; j4 ; ++j ) /*畫按鈕*/

{

for( i=0 ; i5 ; ++i )

{

setfillstyle(SOLID_FILL, color);

setcolor(RED);

bar( x, y, x+width, y+height ); /*畫一個(gè)矩形條*/

rectangle( x, y, x+width, y+height );

sprintf(str2,"%c",str1[j*5+i]);

/*將字符保存到str2中*/

outtextxy( x+(width/2), y+height/2, str2);

x =x+width+ (width / 2) ; /*移動(dòng)列坐標(biāo)*/

}

y +=(height/2)*3; /* 移動(dòng)行坐標(biāo)*/

x =2*width-width/2; /*復(fù)位列坐標(biāo)*/

}

x0=2*width;

y0=3*height;

x=x0;

y=y0;

gotoxy(x,y); /*移動(dòng)光標(biāo)到x,y位置*/

arrow(); /*顯示光標(biāo)*/

putimage(x,y,rar,XOR_PUT);

m=0;

n=0;

strcpy(str2,""); /*設(shè)置str2為空串*/

while((v=specialkey())!=45) /*當(dāng)壓下Alt+x鍵結(jié)束程序,否則執(zhí)行下面的循環(huán)*/

{

while((v=specialkey())!=ENTER) /*當(dāng)壓下鍵不是回車時(shí)*/

{

putimage(x,y,rar,XOR_PUT); /*顯示光標(biāo)圖象*/

if(v==RIGHT) /*右移箭頭時(shí)新位置計(jì)算*/

if(x=x0+6*width)

/*如果右移,移到尾,則移動(dòng)到最左邊字符位置*/

{

x=x0;

m=0;

}

else

{

x=x+width+width/2;

m++;

} /*否則,右移到下一個(gè)字符位置*/

if(v==LEFT) /*左移箭頭時(shí)新位置計(jì)算*/

if(x=x0)

{

x=x0+6*width;

m=4;

} /*如果移到頭,再左移,則移動(dòng)到最右邊字符位置*/

else

{

x=x-width-width/2;

m--;

} /*否則,左移到前一個(gè)字符位置*/

if(v==UP) /*上移箭頭時(shí)新位置計(jì)算*/

if(y=y0)

{

y=y0+4*height+height/2;

n=3;

} /*如果移到頭,再上移,則移動(dòng)到最下邊字符位置*/

else

{

y=y-height-height/2;

n--;

} /*否則,移到上邊一個(gè)字符位置*/

if(v==DOWN) /*下移箭頭時(shí)新位置計(jì)算*/

if(y=7*height)

{

y=y0;

n=0;

} /*如果移到尾,再下移,則移動(dòng)到最上邊字符位置*/

else

{

y=y+height+height/2;

n++;

} /*否則,移到下邊一個(gè)字符位置*/

putimage(x,y,rar,XOR_PUT); /*在新的位置顯示光標(biāo)箭頭*/

}

c=str1[n*5+m]; /*將字符保存到變量c中*/

if(isdigit(c)||c=='.') /*判斷是否是數(shù)字或小數(shù)點(diǎn)*/

{

if(flag==-1) /*如果標(biāo)志為-1,表明為負(fù)數(shù)*/

{

strcpy(str2,"-"); /*將負(fù)號連接到字符串中*/

flag=1;

} /*將標(biāo)志值恢復(fù)為1*/

sprintf(temp,"%c",c); /*將字符保存到字符串變量temp中*/

strcat(str2,temp); /*將temp中的字符串連接到str2中*/

setfillstyle(SOLID_FILL,color+3);

bar(2*width+width/2,height/2,15*width/2,3*height/2);

outtextxy(5*width,height,str2); /*顯示字符串*/

}

if(c=='+')

{

num1=atof(str2); /*將第一個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

strcpy(str2,""); /*將str2清空*/

act=1; /*做計(jì)算加法標(biāo)志值*/

setfillstyle(SOLID_FILL,color+3);

bar(2*width+width/2,height/2,15*width/2,3*height/2);

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

if(c=='-')

{

if(strcmp(str2,"")==0) /*如果str2為空,說明是負(fù)號,而不是減號*/

flag=-1; /*設(shè)置負(fù)數(shù)標(biāo)志*/

else

{

num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

strcpy(str2,""); /*將str2清空*/

act=2; /*做計(jì)算減法標(biāo)志值*/

setfillstyle(SOLID_FILL,color+3);

bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

}

if(c=='*')

{

num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

strcpy(str2,""); /*將str2清空*/

act=3; /*做計(jì)算乘法標(biāo)志值*/

setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

if(c=='/')

{

num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

strcpy(str2,""); /*將str2清空*/

act=4; /*做計(jì)算除法標(biāo)志值*/

setfillstyle(SOLID_FILL,color+3);

bar(2*width+width/2,height/2,15*width/2,3*height/2);

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

if(c=='^')

{

num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

strcpy(str2,""); /*將str2清空*/

act=5; /*做計(jì)算乘方標(biāo)志值*/

setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/

bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

if(c=='%')

{

num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

strcpy(str2,""); /*將str2清空*/

act=6; /*做計(jì)算模運(yùn)算乘方標(biāo)志值*/

setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/

bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

if(c=='=')

{

num2=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/

switch(act) /*根據(jù)運(yùn)算符號計(jì)算*/

{

case 1:result=num1+num2;break; /*做加法*/

case 2:result=num1-num2;break; /*做減法*/

case 3:result=num1*num2;break; /*做乘法*/

case 4:result=num1/num2;break; /*做除法*/

case 5:result=pow(num1,num2);break; /*做x的y次方*/

case 6:result=fmod(num1,num2);break; /*做模運(yùn)算*/

}

setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/

bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結(jié)果區(qū)*/

sprintf(temp,"%f",result); /*將結(jié)果保存到temp中*/

outtextxy(5*width,height,temp); /*顯示結(jié)果*/

}

if(c=='c')

{

num1=0; /*將兩個(gè)操作數(shù)復(fù)位0,符號標(biāo)志為1*/

num2=0;

flag=1;

strcpy(str2,""); /*將str2清空*/

setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/

bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結(jié)果區(qū)*/

outtextxy(5*width,height,"0."); /*顯示字符串*/

}

if(c=='Q')exit(0); /*如果選擇了q回車,結(jié)束計(jì)算程序*/

}

putimage(x,y,rar,XOR_PUT); /*在退出之前消去光標(biāo)箭頭*/

return; /*返回*/

}

/*窗口函數(shù)*/

void mwindow( char *header )

{

int height;

cleardevice(); /* 清除圖形屏幕 */

setcolor( MaxColors - 1 ); /* 設(shè)置當(dāng)前顏色為白色*/

setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 設(shè)置視口大小 */

height = textheight( "H" ); /* 讀取基本文本大小 */

settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*設(shè)置文本樣式*/

settextjustify( CENTER_TEXT, TOP_TEXT );/*設(shè)置字符排列方式*/

outtextxy( MaxX/4, 2, header ); /*輸出標(biāo)題*/

setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*設(shè)置視口大小*/

drawboder(); /*畫邊框*/

}

void drawboder(void) /*畫邊框*/

{

struct viewporttype vp; /*定義視口類型變量*/

setcolor( MaxColors - 1 ); /*設(shè)置當(dāng)前顏色為白色 */

setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*設(shè)置畫線方式*/

getviewsettings( vp );/*將當(dāng)前視口信息裝入vp所指的結(jié)構(gòu)中*/

rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*畫矩形邊框*/

}

/*設(shè)計(jì)鼠標(biāo)圖形函數(shù)*/

int arrow()

{

int size;

int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定義多邊形坐標(biāo)*/

setfillstyle(SOLID_FILL,2); /*設(shè)置填充模式*/

fillpoly(8,raw); /*畫出一光標(biāo)箭頭*/

size=imagesize(4,4,16,16); /*測試圖象大小*/

rar=malloc(size); /*分配內(nèi)存區(qū)域*/

getimage(4,4,16,16,rar); /*存放光標(biāo)箭頭圖象*/

putimage(4,4,rar,XOR_PUT); /*消去光標(biāo)箭頭圖象*/

return 0;

}

/*按鍵函數(shù)*/

int specialkey(void)

{

int key;

while(bioskey(1)==0); /*等待鍵盤輸入*/

key=bioskey(0); /*鍵盤輸入*/

key=key0xff? key0xff:key8; /*只取特殊鍵的掃描值,其余為0*/

return(key); /*返回鍵值*/

}

用C語言編寫三角函數(shù)計(jì)算器,怎樣寫

首先輸入要計(jì)算什么

比如

sin

cos

...

然后輸入要計(jì)算的值

接著調(diào)用對應(yīng)的數(shù)學(xué)函數(shù)就可以了

sin

con

tan

cot這些都是有對應(yīng)數(shù)學(xué)函數(shù)的

最后輸出結(jié)果。

需要注意的是

C的數(shù)學(xué)三角函數(shù)都是弧度做參數(shù)

而不是角度。

新聞名稱:c語言中數(shù)學(xué)庫函數(shù)計(jì)算器 c語言的計(jì)算器
當(dāng)前路徑:http://muchs.cn/article16/docdodg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、網(wǎng)站設(shè)計(jì)公司、Google標(biāo)簽優(yōu)化、企業(yè)建站網(wǎng)頁設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司