c語(yǔ)言formula函數(shù) r語(yǔ)言formula函數(shù)

c語(yǔ)言編一個(gè)四則運(yùn)算程序,如(a+b)*(a-b)+c/d 然后由我隨機(jī)輸入四個(gè)字符 計(jì)算機(jī)就可進(jìn)行運(yùn)算

#include

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、雅安服務(wù)器托管、營(yíng)銷(xiāo)軟件、網(wǎng)站建設(shè)、長(zhǎng)壽網(wǎng)站維護(hù)、網(wǎng)站推廣。

stdio.h

void

main(void)

{

int

a=0,b=0,c=0,d=0;

int

formula=0;

printf("請(qǐng)輸入四個(gè)整數(shù):\n");

scanf("%d

%d

%d

%d",a,b,c,d);

formula=(a+b)*(a-b)+c/d;

printf("%d\n",formula);

}

這是計(jì)算整數(shù)的 

如果小數(shù) 就要把int

改為double或float

如果是字符就是要 char

求問(wèn)C語(yǔ)言寫(xiě)一個(gè)float函數(shù),其返回值和在函數(shù)內(nèi)數(shù)值不同,是怎么回事

可能是語(yǔ)法不規(guī)范,導(dǎo)致的編譯器的問(wèn)題。

函數(shù)原型最好提前聲明,特別是float強(qiáng)制轉(zhuǎn)換成double的情況。

編譯通過(guò)的代碼貼在了Ubuntu pastebin中:鏈接

圖片預(yù)覽:

你可以通過(guò)這個(gè)網(wǎng)站在線驗(yàn)證一下:鏈接

求按要求用C語(yǔ)言作的一個(gè)計(jì)算器

計(jì)算器的c語(yǔ)言程序設(shè)計(jì)

一.功能概述:本程序能計(jì)算帶二重括號(hào)的計(jì)算式的結(jié)果,如輸入((3+2)*(3+2)+5)*((3+2)*(3+2)+5)*(5+5)= 將輸出結(jié)果為9000

二.源程序:

#includestdio.h

int w;

double B[4][40];

shuru(char *pt)

{

int i=0,m;

do

{

*(pt+i)=getchar();

m=i;

i++;

}

while(*(pt+m)!='=');

*(pt+m)='+';

*(pt+m+1)='=';

}

tlchli(char *p)

{

int a,b;

if(*p=='-'||*p=='+')

{

for(b=0;*(p+b)!='=';b++)

;

for(;b=0;b--)

*(p+b+1)=*(p+b);

*p='0';

}

else

{

for(a=1;*(p+a)!='=';a++)

{

if(*(p+a)=='-'||*(p+a)=='+')

{

if(*(p+a-1)=='('*(p+a+1)='0'*(p+a+1)='9')

{

for(b=0;*(p+a+b)!='=';b++)

;

for(;b=0;b--)

*(p+a+b+1)=*(p+a+b);

*(p+a)='0';

a=(a+1);

}

}

}

}

}

jgh(double B[4][40],char *p)

{

int a,b,c=0,d,e,f,h,i,k,n,m;

double g=0,j=0;

for(a=0;a4;a++)

for(b=0;b40;b++)

B[a]=0;

for(d=0;*(p+d)!='=';d++)

{

if(*(p+d)=='+'||*(p+d)=='-'||*(p+d)=='*'||*(p+d)=='/')

{

if(*(p+d)=='+') B[3][c]='+';

if(*(p+d)=='-') B[3][c]='-';

if(*(p+d)=='*') B[3][c]='*';

if(*(p+d)=='/') B[3][c]='/';

if(*(p+d-1)==')'*(p+d-2)==')')

{

B[0][c]=')';

B[1][c]=')';

}

if(*(p+d-1)==')'*(p+d-2)!=')')

B[1][c]=')';

for(e=d-1;*(p+e)'0'||*(p+e)'9';e--)

;

for(f=e;*(p+f)!='.'(f0)*(p+f)='0'*(p+f)='9';f--)

;

if(*(p+f)=='.')

{

for(h=f-1;(h=0)*(p+h)='0'*(p+h)='9';h--)

;

h++;

if(*(p+h-1)=='('*(p+h-2)=='(')

{

B[0][c]='(';

B[1][c]='(';

}

if(*(p+h-1)=='('*(p+h-2)!='(')

B[1][c]='(';

for(i=h;*(p+i)='0'*(p+i)='9';i++)

g=(*(p+i)-48)+g*10.0;

for(k=f+1;*(p+k)='0'*(p+k)='9';k++)

;

k--;

for(n=k;*(p+n)='0'*(p+n)='9';n--)

j=(j/10.0+(*(p+n)-48)/10.0);

B[2][c]=(g+j);

g=j=0;

}

else

{

for(m=e;*(p+m)='0'*(p+m)='9';m--);

m++;

if(*(p+m-1)=='('*(p+m-2)=='(')

{

B[0][c]='(';

B[1][c]='(';

}

if(*(p+m-1)=='('*(p+m-2)!='(')

B[1][c]='(';

for(i=m;*(p+i)='0'*(p+i)='9';i++)

g=(*(p+i)-48)+g*10.0;

B[2][c]=g;

g=0;

}

c++;

}

}

w=(c-1);

}

qkh1(double B[4][40])

{

int a=1,b,c,d,e,f,j,k;

for(b=0;bw;b++)

{

if(B[a]=='(')

{

for(c=b;B[a][c]!=')';c++)

;

for(d=b+1;B[a][d]!='('dc;d++)

;

if(B[a][d]=='(')

k=d;

else

k=b;

B[a][k]=0;B[a][c]=0;

for(e=k;ec;e++)

{

if(B[3][e]=='*')

{

B[2][e+1]=B[2][e]*B[2][e+1];

if(B[3][e-1]=='-'(e0))

{

B[2][e]=0;

B[3][e]='-';

}

else

{

B[2][e]=0;

B[3][e]='+';

}

}

if(B[3][e]=='/')

{

B[2][e+1]=B[2][e]/B[2][e+1];

if(B[3][e-1]=='-'e0)

{

B[2][e]=0;

B[3][e]='-';

}

else

{

B[2][e]=0;

B[3][e]='+';

}

}

}

for(f=k;fc;f++)

{

if(B[3][f]=='+')

{

B[2][f+1]=B[2][f]+B[2][f+1];

B[2][f]=0;B[3][f]='+';

}

if(B[3][f]=='-')

{

B[2][f+1]=B[2][f]-B[2][f+1];

B[2][f]=0;B[3][f]='+';

}

}

b=c-1;

if(B[3][k-1]=='*'k0)

{

for(;kc;k++)

{

B[3][k]='*';

B[2][k]=1.0;

}

}

if(B[3][k-1]=='/'k0)

{

for(;kc;k++)

{

B[3][k]='/';

B[2][k]=1.0;

}

}

}

}

for(j=0;j=w;j++)

{

if(B[1][j]!='('B[1][j]!=')')

B[1][j]=B[0][j];

}

}

qkh2(double B[4][40])

{

int a,b,c,d,e,f,j;

for(b=0;bw;b++)

{

if(B[1]=='(')

{

for(c=b;B[1][c]!=')';c++)

;

B[1]=0;B[1][c]=0;

for(e=b;ec;e++)

{

if(B[3][e]=='*')

{

B[2][e+1]=B[2][e]*B[2][e+1];

if(B[3][e-1]=='-'(e0))

{

B[2][e]=0;

B[3][e]='-';

}

else

{

B[2][e]=0;

B[3][e]='+';

}

}

if(B[3][e]=='/')

{

B[2][e+1]=B[2][e]/B[2][e+1];

if(B[3][e-1]=='-'(e0))

{

B[2][e]=0;

B[3][e]='-';

}

else

{

B[2][e]=0;

B[3][e]='+';

}

}

}

for(f=b;fc;f++)

{

if(B[3][f]=='+')

{

B[2][f+1]=B[2][f]+B[2][f+1];

B[2][f]=0;B[3][f]='+';

}

if(B[3][f]=='-')

{

B[2][f+1]=B[2][f]-B[2][f+1];

B[2][f]=0;B[3][f]='+';

}

}

if(B[3][b-1]=='*'b0)

{

for(;bc;b++)

{

B[3]='*';

B[2]=1.0;

}

}

if(B[3][b-1]=='/'b0)

{

for(;bc;b++)

{

B[3]='/';

B[2]=1.0;

}

}

}

}

}

jshjg(double B[4][40])

{

int b,d,e,f;

for(e=0;ew;e++)

{

if(B[3][e]=='*')

{

B[2][e+1]=B[2][e]*B[2][e+1];

if(B[3][e-1]=='-'e0)

{

B[2][e]=0;

B[3][e]='-';

}

else

{

B[2][e]=0;

B[3][e]='+';

}

}

if(B[3][e]=='/')

{

B[2][e+1]=B[2][e]/B[2][e+1];

if(B[3][e-1]=='-'e0)

{

B[2][e]=0;

B[3][e]='-';

}

else

{

B[2][e]=0;

B[3][e]='+';

}

}

}

for(f=0;fw;f++)

{

if(B[3][f]=='+')

{

B[2][f+1]=B[2][f]+B[2][f+1];

B[2][f]=0;B[3][f]='+';

}

if(B[3][f]=='-')

{

B[2][f+1]=(B[2][f]-B[2][f+1]);

B[2][f]=0;B[3][f]='+';

}

}

}

shuchu(double B[4][40],char *p)

{

printf("answer %f\n",B[2][w]);

}

main()

{

char *p,A[100];

shuru(A);

p=A[0];

tlchli(p);

jgh(B,p);

qkh1(B);

qkh2(B);

jshjg(B);

shuchu(B,p);

}

#include"string.h"

#include"graphics.h"

#include"conio.h"

#include"dos.h"

#include"time.h"

#include"stdlib.h"

#include"stdio.h"

#include"math.h"

/*調(diào)用一系列的庫(kù)函數(shù)*/

int py;/*定義一個(gè)全局變量*/

void mode(int py)/*mode函數(shù),用來(lái)設(shè)置的,來(lái)使用計(jì)算器的多種運(yùn)算功能*/

{ double x1,x2,ans,ans2;

if(py11)

{ printf("input x1,x2:");

scanf("%lf,%lf",x1,x2); }

else {printf("input x:");scanf("%lf",x1);}

switch(py)

{ case 6 : ans=x1+x2;printf("=%.3lf",ans);break;

case 7 : ans=x1-x2;printf("=%.3lf",ans);break;

case 8 : ans=x1*x2;printf("=%.3lf",ans);break;

case 9 : ans=x1/x2;printf("=%.3lf",ans);break;

case 10 : ans=pow(x1,x2);printf("x^%.1lf=%.3lf",x2,ans);break;

case 11 : ans=sqrt(x1);printf("=%.3lf",ans);break;

case 12 : ans=sin(x1);ans2=cos(x1);printf("sin x=%.3lf,cos x=%.3lf",ans,ans2);break;

case 13 : ans=asin(x1);ans2=acos(x1);printf("asin x=%.3lf,acos x=%.3lf",ans,ans2);break;

}

getch();clrscr();

}

int join(char *ps) /*join函數(shù)是輸入用戶名和密碼的,可于已注冊(cè)的用戶進(jìn)行匹配,注冊(cè)用戶可使用高級(jí)功能*/

{ char name[30],pass[20];

int len,i;

printf("ID:");

scanf("%s",name);

printf("\npass word:");

scanf("%s",pass);

clrscr();

for(i=0;istrlen(ps);i++)

if(pass[i]!=*(ps+i)) return 0;

return 1;

}

int menu(int pass)/*menu函數(shù),菜單*/

{int py=6;char key=0;

gotoxy(1,4);

printf("MENU\n\n");

printf("ADD +\n");

printf("SUB -\n");

printf("MUL *\n");

printf("DIV /");

gotoxy(10,6);printf("-");

if(pass) {gotoxy(1,10);printf("INV ^\n");

printf("EVO ~\n");

printf("SIN COS\n");

printf("ASIN ACOS\n");

printf("modify\n");

printf("QUIT"); }

else {gotoxy(1,10);printf("QUIT");}

while(key!=13) /*以下都是控制選擇箭頭的位子的語(yǔ)句*/

{ key=getch();

switch(key)

{ case 80 : gotoxy(10,py);printf(" ");if(!pass) py=py%5+6; else {++py;if(py==16) py=6;}break;

case 72 : gotoxy(10,py);printf(" ");--py; if(py==5) py=10+5*pass; break;

}

gotoxy(10,py);printf("-");

}

return py;

}

main() /*主函數(shù),關(guān)于函數(shù)分配和開(kāi)始動(dòng)畫(huà)的語(yǔ)句*/

{ int gd=DETECT,gm,x=320,y=10,i,l=10,h=10,t,co=3,v=0;

int pass;

FILE *fp;char ps[20];

initgraph(gd,gm,"");/*初始化圖形模式*/

registerbgidriver(EGAVGA_driver);

for(i=1;i31;co=(co++%10),v++,y+=2+v,i++)

{ delay(9e10);cleardevice();

setcolor(co);

setfillstyle(1,co);

sector(x,y,0,360,l,h);/*畫(huà)圓*/

}

for(i=1;i300;i++)

{ setcolor(i%10);

circle(x,y,i);

delay(1000);/*延時(shí)*/

}

cleardevice();/*清屏*/

closegraph();

fp=fopen("file1","r");

if(fp==NULL) pass=1;

else {fgets(ps,20,fp);

pass=join(ps);}

ld: py=menu(pass);

if(py==pass*5+10) {clrscr();printf("bye bye!");getch();return 0;}

else if(py!=14){clrscr();mode(py);} else { fp=fopen("file1","w");

printf("\npass word:");

scanf("%s",ps);

fputs(ps,fp);

fclose(fp); getch();clrscr();

}

goto ld; /*函數(shù)內(nèi)跳轉(zhuǎn)*/

}

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

struct s_node

{

int data;

struct s_node *next;

};

typedef struct s_node s_list;

typedef s_list *link;

link operator=NULL;

link operand=NULL;

link push(link stack,int value)

{

link newnode;

newnode=(link) malloc(sizeof(s_list));

if(!newnode)

{

printf("\nMemory allocation failure!!!");

return NULL;

}

newnode-data=value;

newnode-next=stack;

stack=newnode;

return stack;

}

link pop(link stack,int *value)

{

link top;

if(stack !=NULL)

{

top=stack;

stack=stack-next;

*value=top-data;

free(top);

return stack;

}

else

*value=-1;

}

int empty(link stack)

{

if(stack==NULL)

return 1;

else

return 0;

}

int is_operator(char operator)

{

switch (operator)

{

case '+': case '-': case '*': case '/': return 1;

default:return 0;

}

}

int priority(char operator)

{

switch(operator)

{

case '+': case '-' : return 1;

case '*': case '/' : return 2;

default: return 0;

}

}

int two_result(int operator,int operand1,int operand2)

{

switch(operator)

{

case '+':return(operand2+operand1);

case '-':return(operand2-operand1);

case '*':return(operand2*operand1);

case '/':return(operand2/operand1);

}

}

void main()

{

char expression[50];

int position=0;

int op=0;

int operand1=0;

int operand2=0;

int evaluate=0;

printf("\nPlease input the inorder expression:");

gets(expression);

while(expression[position]!='\0'expression[position]!='\n')

{

if(is_operator(expression[position]))

{

if(!empty(operator))

while(priority(expression[position])= priority(operator-data)

!empty(operator))

{

operand=pop(operand,operand1);

operand=pop(operand,operand2);

operator=pop(operator,op);

operand=push(operand,two_result(op,operand1,operand2));

}

operator=push(operator,expression[position]);

}

else

operand=push(operand,expression[position]-48);

position++;

}

while(!empty(operator))

{

operator=pop(operator,op);

operand=pop(operand,operand1);

operand=pop(operand,operand2);

operand=push(operand,two_result(op,operand1,operand2));

}

operand=pop(operand,evaluate);

printf("The expression [%s] result is '%d' ",expression,evaluate);

getch();

}

求教C語(yǔ)言大神?。?!

scanf("%d,n); 漏了一個(gè)雙引號(hào),應(yīng)該改成scanf("%d",n);

其實(shí)代碼沒(méi)什么別的問(wèn)題了,如果你說(shuō)程序直接退出了,應(yīng)該就是你輸入scanf以后輸入的回車(chē)被getchar()讀到了??梢栽趓eturn 0; 之前加一句system("pause"); 加上頭文件#include stdlib.h

新聞名稱(chēng):c語(yǔ)言formula函數(shù) r語(yǔ)言formula函數(shù)
文章地址:http://muchs.cn/article12/docogdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、、動(dòng)態(tài)網(wǎng)站云服務(wù)器、做網(wǎng)站網(wǎng)站策劃

廣告

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

成都app開(kāi)發(fā)公司