① 怎么用c语言编写一个随机两位数的加减法的程序
//程序如下,加法 减法各25道
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void main()
{
int i,a,b,c,score=0;
srand((unsigned)time(NULL));
for(i=1;i<=50;i++)
{ a=rand()%89+10;
b=rand()%89+10;
c=rand()%198;
if(i<=25)
{
printf("%d+%d=%d\n",a,b,c);
if(c==a+b)
{printf("正确!\n");
score+=2;
}
else
printf("错误!\n");
}
else
{
printf("%d-%d=%d\n",a,b,c);
if(c==a-b)
{printf("正确!\n");
score+=2;
}
else
printf("错误!\n");
}
}
printf("总分为:%d\n",score);
}
② 用C语言编写两个两位数加法运算
#include <stdio.h>
int main()
{
int n,j,k;
printf("1:");
scanf("%d",&j);
printf("渗滚2:");
scanf("%d",&k);
n=j+k;
printf("携粗%d+%d=%d\n"丛隐余,j,k,n);
return 0;
}
③ 求教:C语言两个数的加法算法。
#include <stdio.h>
void main()
{
float a,b,result;
int flag;
for(flag=1;flag==1;)
{
printf("请分别输入需要求和的两数a=");
scanf("%f",&a);
printf("b=");
scanf("%f",&b);
result=a+b;
printf("两数之和为%f\n",result);
flag=3;
for(;(flag!=1)&&(flag!=2);)
{
printf("1、继续,2、退出\n");
scanf("%d",&flag);
if(flag!=1&&flag!=2)
printf("请按正确的格式输入\n");
}
}
}
这段代码可以实现两个浮点数的加法,并且有友好的人机对话。算完一次后,可以通过提示输入决定是否继续程序
④ C语言:编写一个简单的两位数加法、减法、乘法、除法计算程序,要求输入格式:先输入第一个数字
#include<stdio.h>
int main()
{ int a,b,c;
char op;
scanf("%d%c%d",&a,&op,&b);
switch(op)
{ case '+':
c=a+b;
break;
case '-':
c=a-b;
break;
case '*':
c=a*b;
break;
case '/':
c=a/b;
break;
default:
printf("Error!\n");
return 0;
}
printf("%d%c%d=%d\n",a,op,b,c);
return 0;
}
⑤ C语言的两个数相加怎么写
int a,b,c;
scanf("%d%d",&a,&b); //输入a,b
c=a+b; //两数相加给c
printf("%d",c); //输出c
⑥ c语言 小学生两位数与两位数加法测验程序,要求用户可以指定题目数量,练习结束后报告正确与错误的题目数
#include <stdio.h>
#include <stdlib.h>
int main()
{
int TestNum;
int Adder1, Adder2, Result;
int RandSeed;
int i;
int Record = 0;
printf("Please Enter Total Test Number!\n");
scanf("%d", &TestNum);
if (TestNum <= 0)
{
printf("Sorry,Please Input A Positive Integer\n");
exit(0);
}
for (i = 0; i <槐烂 TestNum; i++)
{
srand(i);
Adder1 = (unsigned)rand() % 100;
Adder2 = (unsigned)rand() % 100;
printf("N%d: %2d + %2d = ?\n"滑高, i, Adder1, Adder2);
printf("Please Enter The Result\n");
scanf("%d", &Result);
if (Result == Adder1 + Adder2)
{
printf("Congratuations! It is right.\n\n");
Record++;
}
else
{
printf("Oh, No, Please Try Again\n\n");
}
}
printf("Right:%d\n",Record);
printf("Wrong:%d\n",TestNum - Record);
printf("Right Ratio:%3.2f%%\n",(float)Record * 100 / TestNum);
return 0;
}
编译环铅让漏境:C-Free 5.0 @Windows Xp
⑦ C语言如何算两个小数加法,不用double,
加法不会改变精度,和用不用double没什滑局么关系。乘法是需要考虑精度的,可以自己则让凯定义一个数据类,用数组或者什么其他的来存储每一位的数字,然后孙唤各种运算就写成算法好了。
⑧ c语言小程序 输入两位数实现加减乘除 保留两位小数
#include<stdio.h>
it main()
{int a,b;
scanf("%d%d",&a,&b);
printf("%d+%d=%d\n",a+b);
printf("%d-%d=%d\n",a-b);
printf("%d*%d=%d\n",a*b);
printf("%d/%d=%.2f\n",(float)a/b);
return 0;
}
⑨ 编写程序实现两个小数相加,C语言题目
#include <stdio.h> main () { float vr1,vr2; printf("\n输入两个实数,用逗号隔开\n"); scanf("%f,%f",&vr1,&vr2); printf("\nf% + %f = %f\n",vr1 + vr2);}
⑩ 用C语言编写一个二位数加减法测验程序,要求:
#include "stdio.h"
#include "stdlib.h"
void main()
{
int a,b,answer,t;
int score=0;
int i=0;
int total=0;
int correct=0;
while(score<100)
{
a=(rand()+10)%100;
b=(rand()+10)%100;
if((i++)%2)
{
printf("%d+%d=",a,b);
scanf("%d",&answer);
if(a+b==answer)
{
score+=2;
correct++;
}
else
{
printf("Again:");
scanf("%d",&answer);
if(a+b==answer)
{
score+=1;
correct++;
}
}
}
else
{
if(a<b)
{
t=a;
a=b;
b=t;
}
printf("%d-%d=",a,b);
scanf("%d",&answer);
if(a-b==answer)
{
score+=2;
correct++;
}
else
{
printf("Again:");
scanf("%d",&answer);
if(a-b==answer)
{
score+=1;
correct++;
}
}
}
printf("score:%d\n",score);
total++;
}
printf("Precition:%d%%\n",100*correct/total);
}