帮忙写一个C语言的程序 简单的计算器程序 用switch语句编程设计一个简单的计算器程序。要求根据

作者&投稿:苍沈 (若有异议请与网页底部的电邮联系)
用switch语句编程设计一个简单的计算器程序~

#include
int main( )
{
double a, b;
char op;
scanf("%lf%c%lf", &a, &op, &b);
switch (op)
{
case '+':
printf("%lf + %lf = %lf
", a, b, a + b);
break;
case '-':
printf("%lf - %lf = %lf
", a, b, a - b);
break;
case '*':
printf("%lf * %lf = %lf
", a, b, a * b);
break;
case '/':
if (b != 0)
printf("%lf / %lf = %lf
", a, b, a / b);
else
printf("除数不能是0!
");
break;
}
}

#include #includeint main(){char input[40];char temp1[20];char temp2[20];char op;int flag=0,flag2=0;bool tempbool=0,tempbool2=0;while (!tempbool){flag=0,flag2=0;tempbool=0,tempbool2=0;gets(input);//整行读取for (int i=0;i<50;i++){if((*(input+i))==' '&&(!tempbool))//获取第一个空格位置 flag记录{flag=i;tempbool=1;}else if (*(input+i)=='/'||*(input+i)=='*'||*(input+i)=='-'||*(input+i)=='+'){if (flag==0){flag=i;}op=*(input+i);}else if((!flag)&&(*(input+i))!=' ')//把第一个数记录在temp1中{temp1[i]=*(input+i);}else if(*(input+i)!=' '&&*(input+i)!='\0')//获取第二个数首位位置 flag2记录{if (flag2==0){flag2=i;}if (!tempbool2){flag2=i;tempbool2=1;}temp2[i-flag2]=*(input+i);//把第二个数记录在temp2中}else if(*(input+i)=='\0'){temp1[flag]='\0';temp2[i-flag2]='\0';break;}}switch (op){case '+':printf("%5.2f
",(atof(temp1)+atof(temp2)));printf("Do you want to contiue?(Y/N or y/n)");break;case '-':printf("%5.2f
",(atof(temp1)-atof(temp2)));printf("Do you want to contiue?(Y/N or y/n)");break;case '*':printf("%5.2f
",(atof(temp1)*atof(temp2)));printf("Do you want to contiue?(Y/N or y/n)");break;case '/':printf("%5.2f
",(atof(temp1)/atof(temp2)));printf("Do you want to contiue?(Y/N or y/n)");break;default:printf("ERROR!
");printf("Do you want to contiue?(Y/N or y/n)");}scanf("%s",&temp1);if (temp1[0]=='Y'||temp1[0]=='y'){tempbool=0;fflush(stdin);//清空输入缓存}}return 1;}




帮忙用c语言写一个关于查找关键字的程序~~~
include<stdio.h> include<string.h> ha(FILE *fp,char *y){char c,k[20];int i=0;if(feof(fp))return 0;while(!feof(fp)){c=fgetc(fp);if(c!='\\n'){k[i]=c;i++;} else {k[i]='\\0';strcpy(y,k);return 0;} } } sho(FILE *fp,char *a){FILE *fp1;int i=0...

用C语言写一个输出水仙花数的程序
include <stdio.h> int main(void){ int a,b,c;for(a=1;a<=9;a++)for(b=0;b<=9;b++)for(c=0;c<=9;c++)if(100*a+10*b+c==a*a*a+b*b*b+c*c*c)printf("%d%d%d\\n",a,b,c);return 0;}

求C语言程序,输入一个班50名学生成绩,从高到低排序输出每名学生成绩和...
写了一个,看看能不能帮到你 include<stdio.h> include<string.h> define NUM 50 void bubblesort(float *grade,char (*num)[20]){ int i,j;float temp;char numtemp[NUM][20];for(i=1;i<NUM;i++)for(j=0;j<NUM-i;j++){ if(grade[j]<grade[j+1]){ temp=grade[j];grade[...

如何用C语言写一个类似命令行的程序,能够不断地从其他程序接收命令并...
cmd.c#include <stdlib.h>int main(void){ system("rec_cmd \\"print hello world\\""); system("rec_cmd \\"print how are you\\""); return 0;}以上两个程序一个发送指令,一个接受指令。关键是 system() 函数,可以嵌入命令行,这样就可以实现将程序指令发给另一个程序了。

C语言 编写一个程序 输入周几号 输出改天的英文名 要求用指针处理_百 ...
1 定义字符串指针数组,指向7个英文单词,分别为周一到周日。2 输入周几号。3 取出对应的英文单词并输出。代码:int main(void) { int n; char *week[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}; scanf("%d",&n); puts(week[n-1]); ...

求编写一个大一水平的C语言程序
include<stdio.h> include<stdlib.h> void print(float *,int,int);void main(){ int a1,a2,b1,b2;float *a,*b;printf("Number of rows in A: ");scanf("%d",&a1);printf("Number of columns in A: ");scanf("%d",&a2);a=(float *)malloc(sizeof(float)*a1*a2); \/\/动...

需要一个输入半径求圆面积的C语言程序
编写程序:include<stdio.h> void main(){ float r,c,s;printf("请输入圆的半径: ");scanf("%f",&r); \/*用于输入一个浮点数据存放于地址&r*\/ c=2*3.1415926*r; \/*计算周长,赋值给C*\/ s=3.1415926*r*r; \/*用于计算面积*\/ printf("周长c=%8.4f;\\n面积s=%8.4f\\...

高分悬赏,急寻一个C语言编写的程序。
while (1)mainmemu();return 1;} void mainmemu()\/\/主菜单 { int choice;system ("cls");printf ("\\n\\t\\t***学生信息管理系统***");printf ("\\n\\t\\t* *");printf ("\\n\\t\\t* 1.添加学生信息 *");printf ("\\n\\t\\t* *");printf ("\\n\\t\\t* 2.修改学生信息 *");...

请问在C语言中怎么写一个判断一个数是奇数还是偶数的程序啊?
include <stdio.h> int main(void){ int a;printf("请输入一个整数:");scanf("%d",&a);if(a%2==0) printf("%d是偶数\\n",a);else printf("%d是奇数\\n",a);return 0;}

用C语言和数据结构编写一个简单的程序(求源代码)
case 1:strcpy(tmpStr,preStr);strcat(tmpStr,strNum);printf("%s\\r\\n",tmpStr);break;default:tmpStr[0] = 0;for (i=0;i<k;i++){ strcpy(newPreStr,preStr);j = strlen(newPreStr);newPreStr[j] = strNum[i];newPreStr[j+1] = 0;iCnt = 0;for (j=0;j<k;j++){ if(...

龙潭区13381371063: c语言程序编写(初学)(1) 编写一个简单计算器程序,输入格式为:data1 op data2.其中data1和data2是参加运算的两个数,op为运算符,其取值只能是+... -
时转固特:[答案] #includemain(){ char op; float result,data1,data2; float OP(float x,float y,char t); printf("input op(+,-,*,/):\n",op); scanf("%c",&op); printf("input data1:\n",data1); scanf("%f",&data1); pr...

龙潭区13381371063: 用C语言写一个简单的计算器程序可实现简单的加减乘除运算从键盘输入两个数字再输入一个符号(+,—,*,/,%)求这两个数按照指定运算符运算后的结果例输入3,5,*输出“3*5=15” -
时转固特: #include /*库函数*/ 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(!...

龙潭区13381371063: c语言设计一个简单的计算器程序
时转固特: /* 2013年12月23日 12:43:46 目的:计算器的实现 */ # include <stdio.h> # include <ctype.h> # include <math.h> char get_choice(void); //获取用户输入的选项,并建立目 char get_first(void); //获取用户输入的选项,并剔除错误输入 float get_int(...

龙潭区13381371063: C语言 要求编写一个简单计算器的程序 -
时转固特: #include<stdio.h> void add(int a,int b,int c) {c=a+b;printf("%d+%d = %d",a,b,c);printf("\n"); } void minus(int a,int b,int c) {c=a-b;printf("%d-%d=%d",a,b,c);printf("\n"); } void multiplication(int a,int b,int c) {c=a*b;printf("%d*%d=%d...

龙潭区13381371063: 简单的用c语言写一个计算器程序,加减乘除能用就好 -
时转固特: #include"stdio.h" void main() { float a,b,c; char e; printf("input a,e,b\n");/*输入两个数和符号,例如3+8*/ scanf("%f%c%f",&a,&e,&b); switch(e) { case '+':c=a+b;break; case '-':c=a-b;break; case '*':c=a*b;break; case '/': if(b==0.0) printf("error\n"); else c=a/b;break; } printf("%f%c%f=%f",a,e,b,c); }

龙潭区13381371063: 用C语言编写简易计算器程序 -
时转固特: 原发布者:持剑观风#include#includeintmain(void){intchoice,t=1;printf("**********************计算器*****************************************\n");printf("1.加法运算2.减法运算\n");printf("3.乘法运算4.除法运算\n");printf("5.平方运算6.开方运算\n...

龙潭区13381371063: C语言要编写一个计算器的简单程序! 急需急需
时转固特: #include <stdio.h> int main() { float a,b; char c,i='a'; for(;i!='0';) { printf("请输入要运算的表达式:"); scanf("%f%c%f",&a,&c,&b); switch(c) { case '+':printf("运算的结果是:%f\n",a+b);break; case '-':printf("运算的结果是:%f\n",a-...

龙潭区13381371063: 求一个简单的c语言程序 -
时转固特: #include <stdio.h>//定义输入点个数 #define NODE_NUM 4typedef struct Nodetag {//点名称char c;//点xint x;//点yint y; }Node;//两点坐标相减之后的 x+y的值 int substacter(Node *node1, Node *node2) {return (node1->x - node2->x) + (...

龙潭区13381371063: 用C语言编写一个简单加减乘除的程序 -
时转固特: #include <stdio.h> #include <stdlib.h>#include <time.h>main() {int a,b,c,d,result,i;char f[]={'+','-','*','/'};while(1){srand(time(NULL));a=rand()%100;b=rand()%100;c=rand()%4;switch (c){case 0: d=a+b;break;case 1: d=a-b;break;case 2: ...

龙潭区13381371063: 我急需一个用c语言编写的简单的计算器程序代码300行左右 -
时转固特: Input expression(number,+-*/()),return to exit:(2+3)*3+5/(3+2) Parsed result: 1 : ( 99 : 2 3 : + 99 : 3 2 : ) 5 : * 99 : 3 3 : + 99 : 5 6 : / 1 : ( 99 : 3 3 : + 99 : 2 2 : ) Evaled result:16.000000 Input expression(number,+-*/()),return to exit:这是程序运行结果,如能满足要求请私信

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网