三九宝宝网宝宝教育教学论文

c语言编写四则运算法则的程序

03月09日 编辑 39baobao.com

[C语言四则运算程序高手帮帮忙]#include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> int scan() { char s[100]; int i,t,z=0; do { z=0; gets(s); for(i=0;s[i]!='\0';i++) if(s[...+阅读

楼主问用C语言编写,1楼的用C++怎么编写啊

我的C语言代码如下:

#include

#include

#include

#include

#include

void main()

{ int s,d=0;

int a,b,c,z,v,m;

char ch[4]={'+','-','x','/'};

srand((unsigned)time(NULL));

m=100;

b=rand()%m;

printf("%d ",b);

z=b;

for(s=0;s<3;s++)

{a=rand()%4;b=rand()%m;
printf("%c %d ",ch[a],b);
if (a==0) {v=z+b;z=b;}

if (a==1) {v=z-b;z=b;}

if (a==2) {v=z*b;z=b;}

if (a==3) {v=z/b;z=b;}

}

printf("= ");

loop: scanf("%d",&c);

fflush(stdin);

if (c==v) {printf("OK!");goto end;}

while (c!=v & d++!=2)

{printf("it does not matter and try it again: ");
goto loop;
}

printf("the result is : %d",v);

end:getch();

}

C语言四则运算程序高手帮帮忙!

#include #include #include #include int scan() { char s[100]; int i,t,z=0; do { z=0; gets(s); for(i=0;s[i]!='\0';i++) if(s[i]<'0' || s[i]>'9') break; if(i>=strlen(s)) for(t=0;s[t]!='\0';t++) z=z*10+((int)s[t]-48); else printf("您的输入有误,请重新输入"); } while(i

1、

2、

3、4\n"); printf("如需退出请输入5\n"); choice=scan(); switch(choice) { case 1:printf("欢迎来到加法运算测试系统,如需退出请输入9999\n");fuhao='+';break; case 2:printf("欢迎来到减法运算测试系统,如需退出请输入9999\n");fuhao='-';break; case 3:printf("欢迎来到乘法运算测试系统,如需退出请输入9999\n");fuhao='*';break; case 4:printf("欢迎来到除法运算测试系统,如需退出请输入9999\n");fuhao='/';break; case 5:printf("本次测试愉快,欢迎下次再来测试\n"); printf("本次共做%d道题,其中%d道正确,正确率为%f\n",sum,right,precent); break; default:printf("您的输入有误,请重新输入\n");choose(); } } int ans(int x,int y,int choice) { switch(choice) { case 1:z=x+y;break; case 2:z=x-y;break; case 3:z=x*y;break; case 4:z=x/y;break; } return(z); } void yunsuan() { suiji(); printf("%d%c%d=",x,fuhao,y); z=ans(x,y,choice); answer=scan(); if(z==answer) { printf("正确\n"); right++;sum++; yunsuan(); } else if(answer==9999) choose(); else { printf("不正确, 正确答案为%5d\n",z); sum++; yunsuan(); } } void main() { printf("欢迎来到四则运算测试系统\n"); choose(); while(choice!=5) yunsuan(); }

谁可以用C函数编一个四则运算的小程序具体要求如下

#include

#include

#include

void main()

{

int a,b,c;

srand((unsigned)time(NULL));

a=rand()%101;

b=rand()%101;

c=rand()%5;

printf("%-3d%d\n",a,b);

switch(c)

{

case 0:c='+';printf("%d+%d=%d\n",a,b,a+b);break;

case 1:c='-';printf("%d-%d=%d\n",a,b,a-b);break;

case 2:c='*';printf("%d*%d=%d\n",a,b,a*b);break;

case 3:c='/';printf("%f/%f=%f\n",(float)a,(float)b,(float)a/(float)b);break;

case 4:c='%';printf("%d%%%d=%d\n",a,b,a%b);break;

default:printf("错误!");break;

}

}

C语言中的分数四则运算

#include#includemain() { int a,b,c,d,i,x,y; char op; scanf("%d/%d%c%d/%d",&b,&a,&op,&d,&c); if(a==0||c==0) exit(0); if(op=='+'){y=b*c+d*a;x=a*c;} if(op=='-'){y=b*c-d*a,x=a*c;} if(op=='*'){y=b*d;x=a*c;} if(op=='/'){y=b*c;x=a*d;} if(y==0&x!=0) { printf("%d/%d%c%d/%d=0\n",b,a,op,d,c); } else if(x==0) exit(0); //你的这里怎么可以再用一个ELSE呢,条件已经变化了。后面跟前面没有联系啊if(x>y) i=y; while(i>1) { if(x%i==0&y%i==0){x=x/i;y=y/i;continue;} i--; } if(x/i==1) printf("%d/%d%c%d/%d=%d\n",b,a,op,d,c,y); else printf("%d/%d%c%d/%d=%d/%d.\n",b,a,op,d,c,y,x);//不明白你后面这里为什么会多出两个花括号。//由于上不能空行,我也不猜测错误原因。你自己理解下。}//程序运行无误...

以下为关联文档:

C语言四则运算程序高手帮帮忙!#include #include #include #include int scan() { char s[100]; int i,t,z=0; do { z=0; gets(s); for(i=0;s[i]!='\0';i++) if(s[i]'9') break; if(i>=strlen(s)) for(t=...

C语言问题四则运算程序我怀疑你代码的这段有问题: else if(ch == ')') { optr = MathOptr(ch); while(!Stack1Empty(&OptrStack) & Peek1(&OptrStack).stackprecedence >= optr.inputprecedence) //...

求c语言编写四则运算程序#include"stdafx.h" #include #include #include char token;/*global token variable*/ /*function prototypes for recursive calls*/ float exp(void); float term(void);...

C语言编写程序四则运算法则1234567891011121314151617# include <stdio.h>int main(void){ int a,b,s; char c; scanf("%d%c%d",&a,&c,&b); switch(c) { case '+':s=a+b;break; case '-':s=a-b;break; c...

C语言程序编写此题应该属于约瑟夫问题范围。 语句注释,我习惯用了//,请楼主注意哈。 #include"stdlib.h" #include"stdio.h" #define NULL 0 typedef struct point { int data; int NO; struct...

小学生十以内加减法运算程序c语言编写分练习模式和考试模式#include#include#includeusing namespace std; int a,b,dui_ti=0,cuo_ti=0,ti_mu=0; char ch; int sui_ji_shu_a()//生成随机数a { int a; a=rand()%9+1; return a; } int s...

C语言编写的投票程序#include<stdio.h> int main(void) { int i,j,k,count1,count2,count3,count4,count5,vote; count1=count2=count3=count4=count5=0; printf("6001\tzhao\t%d\n6002\tqian\t%...

用if语句编写四则运算的C语言程序#include"stdio.h" void main() { int x,y,z; char c; scanf("%d%d",&x,&y); gtchar(c); switch(c) { case '+': z=x+y; case '-': z=x-y; case '*': z=x*y; case '/': z=x/y; }...

用C语言编写一个程序用C语言编写一个程序,C语言编写程序:#include <stdio.h> main() { char *month_name[13]={"illegal month","January","February","March","April", "May","June","July","August","September","Oct...

推荐阅读
图文推荐