简单计算器实现,参考:
#include<stdio.h>
int main(){
double a,b,w,x,y,z;
char ch;
while(scanf("%lf%c%lf",&a,&ch,&b)!=1){
if(ch=='+'){
y=a+b;
printf("%lf+%lf=%lf\n",a,b,y);
}
if(ch=='-'){
z=a-b;
printf("%lf-%lf=%lf\n",a,b,z);
}
if(ch=='*'){
w=a*b;
printf("%lf*%.lf=%lf\n",a,b,w);
}
if(ch=='/'){
if(b==0)
printf("除数不能等于0");
else{
x=a/b;
printf("%lf/%.lf=%lf\n",a,b,x);
}
}
}
return 0;
}
输入文字用scanf("%s",s)
s是字符数组
char s[100];
另外字符串比较要用 if (strcmp(s,"你")==0)
不能用 if (s=="你")
代码如下:
#include<stdio.h>
#include<string.h>
int main()
{
char s[100];
scanf("%s", s);
printf("s=%s\n",s);
if (strcmp(s,"你")==0)
{
printf("hh");
}
return 0;
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
定义文字?没懂
c定义字符串用char *或者char数组