當前位置:首頁 » 編程語言 » c語言等式加減結果判斷
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言等式加減結果判斷

發布時間: 2022-08-03 18:07:26

① 題目是:隨機產生一個10以內的加減乘除算式,判斷用戶輸入的計算結果判斷用戶計算是否正確,用c語言

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
voidfun()
{
inta,b,c,s,s1;
srand(time(NULL));
a=rand()%9+1;
b=rand()%9+1;
c=rand()%4+1;
switch(c)
{
case1:s=a+b;printf("%d+%d=",a,b);break;
case2:s=a-b;printf("%d-%d=",a,b);break;
case3:s=a*b;printf("%d*%d=",a,b);break;
case4:s=a;printf("%d/%d=",a*b,b);break;
}
scanf("%d",&s1);
if(s==s1)printf("回答正確! ");
elseprintf("回答錯誤!答案是:%d ",s);
}
intmain()
{
while(1)fun();
return0;
}

② C語言如何實現判斷用戶輸入的算式結果正確

將用戶輸入的算式存在字元串中,然後將字元串中的字元轉換成對應的數字和符號,自己算一遍。如果對,則告訴用戶對,如果錯,則告訴用戶錯。

③ 一道c語言程序題:編寫程序實現兩個數的加減計算結果的判斷。

#include<iostream.h>
#include<stdio.h>
int main()
{
double a,b,c,d;
cout<<"1.加法運算 2.減法運算"<<endl;
cin>>a;
if(a==1)
{
cout<<"輸入加數:"<<endl;
cin>>a;
cout<<"輸入被加數:"<<endl;
cin>>b;
cout<<"你的結果:"<<endl;
cin>>d;
c=a+b;
if(c==d)
{
cout<<"perfect"<<endl;
return 0;
}
else
{
cout<<"error"<<endl;
cout<<a<<'+'<<b<<'='<<c<<endl;
return 0;
}
}
if(a==2)
{
cout<<"輸入減數"<<endl;
cin>>a;
cout<<"輸入被減數"<<endl;
cin>>b;
cout<<"你的結果:"<<endl;
cin>>d;
c=a-b;
if(c==d)
{
cout<<"perfect"<<endl;
return 0;
}
else
{
cout<<"error"<<endl;
cout<<a<<'-'<<b<<'='<<c<<endl;
return 0;
}
}
}

④ C語言編寫加減計算程序

#include <stdio.h>

main (void)

{
int a,b,c;
char op;
scanf ("%d%c%d",&a,&op,&b);//最好空格去掉,這樣就可以直接寫成a+b或者a-b。如果有空格的話要記得空格也要打a + b。要不會出現錯誤 ,而且輸入的時候需要用地址符&····

if(op=='+')
{c=a+b;}

if(op=='-')
{c=a-b;}
printf("%d%c%d=%d\n",a,op,b,c);//樓主這句應該放在數據處理完後。。要不你輸出的a,op,b都是在沒處理過的數,也就是原來的值,而且最好是把,去掉,這樣更美觀 ,而且printf後面不需要&。。。切記。而且沒必要那樣輸出。請樓主看我的printf```
}

⑤ c語言編程 判斷只含加減乘除一種運算的等式是否成立

#include<stdio.h>
void main()
{
if(1+1==2)
printf("成立");
else
printf("不成立");
}
不錯

⑥ 編寫程序實現兩個數的加減計算結果的判斷

#include<stdio.h>

void main()

{

int a,b,sum;

printf("請輸入兩個數:");

scanf("%d%d",&a,&b);

printf("請輸入計算結果:");

scanf("%d",&sum);

if(sum==a+b)

printf("結果正確");

else

printf("結果錯誤");

}

後綴表達式

postfix-expression [ expression ],數組下標運算。

postfix-expression ( argument-expression-list),函數調用,括弧內的參數可選。

postfix-expression . identifier,成員訪問

postfix-expression -> identifier,成員訪問,->號之前應為指針。

postfix-expression ++,後綴自增

postfix-expression --,後綴自減

以上內容參考:網路-C語言運算符

⑦ C語言實驗題:編寫程序實現兩個數的加減計算結果並判斷

#include<stdio.h>

void main()
{
int a,b,c;
char m,n;
printf("請輸入等式:");
scanf("%d %c %d %c %d",&a,&m,&b,&n,&c);
if(((int)m==(int)'+' && c==a+b )|| ((int)m==(int)'-' && c==a-b )) printf("Perfect!\n");
else printf("Error!\n");

}

⑧ C語言,判斷a+b等式是否正確

#include<stdio.h>

intmain()
{
inta,b,c;
intn;
scanf("%d",&n);
while(n--)
{
scanf("%d+%d=%d",&a,&b,&c);
if(a+b==c)
printf("Yes ");
elseprintf("No ");
}
}

可以嗎?