當前位置:首頁 » 編程語言 » c語言怎麼把算式輸進去
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言怎麼把算式輸進去

發布時間: 2023-01-10 02:40:35

c語言算式運算

全部少個逗號,比如
printf("%d+%d=%d"a,b,a+b);改為
printf("%d+%d=%d",a,b,a+b);

#include<stdio.h>
void main()
{
int a,b;
char c;
printf("輸入一個由兩個數字和一個算式運算符組成的表達式,完成相應的計算,並將算式和結果輸出\n");
scanf("%d%c%d",&a,&c,&b);
if(c==43)
printf("%d+%d=%d",a,b,a+b);
else
if(c==45)
printf("%d-%d=%d",a,b,a-b);
else
if(c==42)
printf("%d*%d=%d",a,b,a*b);
else
if(c==47)
printf("%d/%d=%d",a,b,a/b);
}

Ⅱ 如何用c語言實現:輸入一個算式,然後在程序中使用。

程序是不認算式的。你只能把它變為系數輸入才可以。如ax*x+bx+c,你輸入a,b,c。直接輸算式沒意義。歸根到底,程序只能做你設計好的事情。想讓它認算式,你要把你的算式歸納成只有系數的東西,或者其它有規律的東西。

Ⅲ C語言如何輸入一個兩個整數運算的計算表達式,輸出該表達式和結果,如:輸入「2*3=」,輸出「2*3=6」

用兩個整形變數a,b,使用庫函數printf 用兩次,兩個變數值分別賦2和3即可。

Ⅳ 在c語言中,如何輸入一串算式,運行後得到結果,算式中包括+-*/()中的幾種

輸入放入字元串數組中,對字元數組進行判斷,如果是(+,-,*,\,等),記錄數組下標。
之後轉化成 int,再進行求值

Ⅳ c語言 從鍵盤上隨意輸入一個算術運算式(可能是加、減、乘、除中

#include<stdio.h>
intadd()
{
inta,b,c;
scanf("%d+%d=%d",&a,&b,&c);
if(c==a+b)
returnprintf("yes");
else
returnprintf("no");
}

intsub()
{
inta,b,c;
scanf("%d-%d=%d",&a,&b,&c);
if(c==a-b)
returnprintf("yes");
else
returnprintf("no");
}

intchu()
{
floata,b,c;
scanf("%f/%f=%f",&a,&b,&c);
if(c==a/b)
returnprintf("yes");
else
returnprintf("no");
}

intcheng()
{
inta,b,c;
scanf("%d*%d=%d",&a,&b,&c);
if(c==a*b)
returnprintf("yes");
else
returnprintf("no");
}

intmain()
{
intnum;
printf("1.加法2.減法3.乘法4.除法0.退出 ");
printf("selecttype:");
scanf("%d",&num);
switch(num)
{
case1:
add();
break;
case2:
sub();
break;
case3:
cheng();
break;
case4:
chu();
break;
case0:
break;
default:
printf("error");
break;
}
}

Ⅵ c語言中開方怎麼輸

一般的來說在進行開方運算時,都會使用sqrt函數進行開方運算。使用sqrt時就需要引用頭文件math.h。(這里使用%d來輸出整數):

#include<stdio.h>

#include<math.h>

int Mysqrt(int n)

{

return sqrt(n*1.0);

}

int main()

{

printf("%d ",Mysqrt(10));

printf("%d ",Mysqrt(9));

return 0;

}

(6)c語言怎麼把算式輸進去擴展閱讀:

C語言編寫注意事項:

1、變數名以字母和數字組成, (下劃線"_"被默認為字元,以下劃線為首寫字母的為庫類變數名),變數常以小寫字母開頭.內部變數命前31位有效,外部名至少前6位保持唯一性、大小寫在C語言中是區分的。

2、一個字元常量為一個整數, 以''單引號括起。 '0' 為48, 與0沒有任何關系。

3、ANSI C語言的轉義符: a 響鈴符;  回退符; f 換頁符; 換行符; 回車符; 橫向製表符 v 縱向製表符; \ 反斜杠; ? 問號; ' 單引號;" 雙引號; ooo 八進制數; xhh 十六進制數;

'' 表示0, 即(null).通常以''形式表示0 以強調某些表達是的字元屬性。

4、'x'與"x"的區別: 'x'表示一個整數, 字母x在極其字元集中對應的數值、"x"表示一個包含一個字元x 以及一個結束符''。

5、const在聲明變數中起限製作用, 該限定變數的值不能被修改。

Ⅶ 怎麼在c語言中輸入1,2,3,4,5,+,=

scanf("%d%d%d%d%d%c%c",&a,&b,&c,&d,&e,&f,&g);
然後你輸入1,2,3,4,5,+,=就行了。

Ⅷ 怎麼用C語言的輸入一個數學式子可以得到結果,如input:3+4 output:7,輸入的式子可以的加減乘除這些簡單的運

這個設計到優先順序 要棧處理
下面這個程序 輸入0結束
輸入其它的+-*/運算式 輸出結果
但是字元與字元間有空格 不然要出錯
比如輸入1 + 2
或者 + 2 * 5 - 7 / 11
注意有空格
#include <iostream>
#include <stack>
#include <string>
#include <string.h>
using namespace std;

int main(){
char ch[210];
int len,i,j;
double n,m,k;

while (cin.getline(ch,210))
{
len = strlen(ch);
if(len==1&&'0' == ch[0])break;

stack<double>s1;
stack<char>s2;
i=0,k=0;
while (i<len)
{
if (' '== ch[i]){
i++;
continue;
}
else if ('0'<=ch[i] && '9'>=ch[i])
{
k = 0;
k = k*10 + ch[i]-'0';
i++;
while ('0'<=ch[i] &&'9'>=ch[i]&&i<len)
{
k = k*10 + ch[i]-'0';
i++;
}
s1.push(k);
k =0;
}
else
{
if ('*'==ch[i] || '/'==ch[i])
{
j =i;
n = s1.top(),s1.pop();
i++;
i++;
k = 0;
while ('0'<=ch[i] && '9'>=ch[i]&&i<len)
{
k = k*10 + ch[i]-'0';
i++;
}
if ('*'==ch[j])
{
k = k*n;
}else{
k = n/k;
}
s1.push(k);
}
else if('+'==ch[i] || '-'==ch[i])
{
s2.push(ch[i]);
i++;
}
}
}

char str, str2;
while (!s2.empty())
{
str = s2.top();
s2.pop();
k = s1.top(),s1.pop();
if ('+' == str)
{
n = s1.top();s1.pop();
if (!s2.empty())
{
str2 = s2.top();

if ('-' == str2)
{
k = n - k;
}else{
k = k + n;
}
}else
k = k + n;
// cout<<k<<endl;
s1.push(k);
}else{
n = s1.top();s1.pop();
if (!s2.empty())
{
str2 = s2.top();
if ('-' == str2)
{
k = k + n;
}else{
k = n - k;
}
}else
k = n - k;
s1.push(k);
}
}
printf("%0.2lf\n",s1.top());s1.pop();
}
return 0;
}

Ⅸ 在C語言中如何輸入以下公式呢

a=W_mm*(1-pow(1-(double)W0/WM,1/(1.0+b)));