當前位置:首頁 » 編程軟體 » 編程寫加減分

編程寫加減分

發布時間: 2022-07-07 10:15:01

c語言編程、一個二位數加減法測驗程序

Score= 3, Right= 2,Wrong= 0,Total= 2
66 + 60 =?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int i,j,tmp,num1,num2,op,answer,flag,cnt,right=0,wrong=0,score=0,quest[10][3]={0};
srand((unsigned)time(NULL));
for (i=0;score<100;i++)
{
num1 = rand()%89+11;
num2 = rand()%89+11;
op = rand()%2;
num1<num2?tmp=num1,num1=num2,num2=tmp:NULL;
op>0?op='+':op='-';
for (j=0;j<i;j++)
{
if (quest[i][0]==num1 && quest[i][1]==op && quest[i][2]==num2)
{
i--;
}
else
{
quest[i][0]=num1;
quest[i][1]=op;
quest[i][2]=num2;
system("cls");
printf("Score=%2d, Right=%2d,Wrong=%2d,Total=%2d\n",score,right,wrong,i);
printf("%2d %c %2d =?",num1,op,num2);
cnt=0;
do
{
flag=0;
scanf("%d",&answer);
if ((op=='+' && answer==num1+num2) || (op=='-' && answer==num1-num2))
{
if (cnt==0)
{
score+=2;
}else
{
score++;
}
right++;
printf("Right!\n");
flag=1;
}else
{
printf("Wrong!\n");
if(cnt==1)
{
wrong++;
break;
}
}
cnt++;
} while (!flag);
}
}
}
}
望採納

❷ 求編程高手幫忙寫個四則運算加減法的程序

char strResult[1024];

typedef int (WINAPI ICEPUB_BIGINTEGERADDITION)(char *str1,char *str2,char *strResult);
ICEPUB_BIGINTEGERADDITION *icePub_bigIntegerAddition = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_bigIntegerAddition = (ICEPUB_BIGINTEGERADDITION *)GetProcAddress(hDLLDrv, "icePub_bigIntegerAddition");
}

if(icePub_bigIntegerAddition != NULL)
{
icePub_bigIntegerAddition("11111111111111111111111","22222222222222222222",strResult);
}
if(hDLLDrv)
FreeLibrary(hDLLDrv);

AfxMessageBox(strResult);

char strResult[1024];

typedef int (WINAPI ICEPUB_BIGINTEGERSUBTRACTION)(char *str1,char *str2,char *strResult);
ICEPUB_BIGINTEGERSUBTRACTION *icePub_bigIntegerSubtraction = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_bigIntegerSubtraction = (ICEPUB_BIGINTEGERSUBTRACTION *)GetProcAddress(hDLLDrv, "icePub_bigIntegerSubtraction");
}

if(icePub_bigIntegerSubtraction != NULL)
{
icePub_bigIntegerSubtraction("11111111111111111111111","22222222222222222222",strResult);
}
if(hDLLDrv)
FreeLibrary(hDLLDrv);

AfxMessageBox(strResult);

支持1024位10進制運算

❸ 怎麼用java編程,實現分數的加減乘除運算

java編程實現分數的加減乘除運算的步驟如下:

1、打開eclipse,創建一個Java工程,在此工程里新建一個類;

2、在新建的類中,添加4個運算類;

3、在主方法中調用對應的方法即可完成分數的加減乘除運算了。

具體實現代碼如下:

publicclassDemo{
publicstaticvoidmain(String[]args){
System.out.println(jia(1,2));
System.out.println(jian(1,2));
System.out.println(cheng(1,2));
System.out.println(chu(1,2));
}
//加法運算
privatestaticfloatjia(floatx,floaty){
returnx+y;
}
//減法運算
privatestaticfloatjian(floatx,floaty){
returnx-y;
}
//乘法運算
privatestaticfloatcheng(floatx,floaty){
returnx*y;
}
//除法運算
privatestaticfloatchu(floatx,floaty){
returnx/y;
}
}

❹ MATLAB中,定積分加減怎麼編程

題主給出的變積分,可以通過循環語句來解決。

第一步,將t劃分若干份,如t=0:100

第二步,使用for循環語句,求解x為某值時的積分值。即

for i=1:100

。。。。。。

%求解x為某值時的積分值

end

第三步,使用integral函數求解積分值,即

t1=t(i);

eq1=@(x)exp(-(x-100).^2/15^2);

eq2=@(x)exp(-(x-50).^2/20^2);

f(i)=integral(eq1,-inf,t1)+quadgk(eq2,t1,+inf);

第四步,使用plot函數,繪制該積分的數值解圖形。

❺ 求教分數加減法的C語言編程

int main()
{
float f1 = 1.0, f2 = 3.0,f3,f4;
f3 = f1 / f2;
f4 = 2.0 / 3.0;
printf("%f\n", f1 / f2);
printf("%f\n", f3 + f4);
printf("%f\n", f3 - f4);
return 0;
}
是這樣嗎?

❻ C語言編寫程序,使能對分數進行加減乘除四則運算 急!求!

就不寫代碼了。。說思路
關鍵的部分大概是結果的呈現吧 分數形式的
首先我們需要重載運算符。。 噢 這是C 沒有。
那麼我們假定是在界面上分別輸入分子和分母 這樣乘除法計算方法顯而易見
加減法則需要利用最小公倍數函數
最後結果的化簡需要利用最大公約數函數

❼ C語言編程 100以內整數加減法

srand(time(0));
inta[20];
for(inti=0;i<20;i++)
{
a[i]=rand()%100;
}
for(inti=10;i<20;i+=2)
{
if(a[i]<a[i+1])
{
intt=a[i];a[i]=a[i+1];a[i+1]=t;
}
}
intscore=0;
for(inti=0;i<20;i+=2)
{
charc=i<10?'+':'-';
printf("%d%c%d=幾? ",a[i],c,a[i+1]);
intx;
scanf("%d",&x);
if((i<10&x=a[i]+a[i+1])|(i>=10&x=a[i]-a[i+1]))
{
score+=10;
cout<"回答正確"<<endl;
}
elsecout<"回答錯誤"<<endl;
}
switch(score)
{
case0:
case10:
case20:
case30:
case40:
case50:cout<<"要加油哦"<<endl;break;
case60:
case70:
case80:cout<<"真不錯哦"<<endl;break;
case90:cout<<"你真棒"<<endl;break;
case100:cout<<"酷斃了"<<endl;break;
default:;
}

❽ c語言編程 高精度加減法

等十分鍾
在給你寫
加法函數
好久沒寫程序了
本來以為十分鍾能寫好
。。。。。(修改:修復了個小bug)
void
plus(char
*a,
char
*b,
char
*c){
int
i,index_a,index_b,index_c,carry=0,ten='9'+1,temp_index_c;
index_a=strlen(a)-1;
//
index變數指向最末一個數字
index_b=strlen(b)-1;
index_c=index_a>index_b?
index_a:index_b;
temp_index_c=index_c;
if(index_a>=index_b){
for(i=index_b+1;i>=0;i--){
b[i+(index_a-index_b)]=b[i];
}
for(i=0;i<index_a-index_b;i++)
b[i]='0';
}
else{
for(i=index_a+1;i>=0;i--){
a[i+(index_b-index_a)]=a[i];
}
for(i=0;i<index_b-index_a;i++)
a[i]='0';
}
while(index_c>=0){
c[index_c]=a[index_c]+b[index_c]+carry-'0';
if(c[index_c]>=ten){
c[index_c]-=ten-'0';
carry=1;
}
else
carry=0;
index_c--;
}
if(carry==1){
for(i=temp_index_c;i>0;i--){
c[i+1]=c[i];
}
c[0]=1;
}
c[temp_index_c+1]=0;
}

熱點內容
lol天使輔助腳本 發布:2025-02-09 11:24:39 瀏覽:139
溯源碼怎麼生成 發布:2025-02-09 11:15:15 瀏覽:442
android70flash 發布:2025-02-09 11:15:06 瀏覽:725
如何查看伺服器拒絕信息 發布:2025-02-09 11:13:07 瀏覽:946
靜態編譯失敗怎麼回事 發布:2025-02-09 11:12:54 瀏覽:215
sql能力 發布:2025-02-09 10:43:50 瀏覽:982
編譯framework 發布:2025-02-09 10:42:11 瀏覽:382
五子棋對戰演算法 發布:2025-02-09 10:12:19 瀏覽:713
php樹菜單 發布:2025-02-09 10:04:10 瀏覽:360
linux保存ip 發布:2025-02-09 10:04:10 瀏覽:24