當前位置:首頁 » 編程語言 » c語言兩位小數加法程序
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言兩位小數加法程序

發布時間: 2023-05-25 09:05:57

① 怎麼用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);
}