當前位置:首頁 » 操作系統 » 數12的源碼

數12的源碼

發布時間: 2023-09-17 06:29:12

① 求輸出數字組合 123456 12345 1234 123 12 1 源代碼

void main(){
int A=123456;
while(A>0){
printf("%d ",A);
A=A/10;
}
}

② 編寫程序來執行兩個數字12和5的算術加法,乘法和除法(java程序)求源代碼

樓上的除法運算出錯,a
/
b取商,a%b取余,同數學運算是有差異的。還有就是雙精度浮點數的加減乘除會損失精度。建議用BigDecimal提供的方法來運算。
如:
BigDecimal
a
=
new
BigDecimal(12);
BigDecimal
b
=
new
BigDecimal(5);
加法運算:a=a.add(b);
減法運算:a=a.subtract(b);
乘法運算:a=a.multiply(b);
除法運算:a=a.divide(b);
獲取運算結果:a.toString()
,
a.longValue()
,
a.intValue()
.....等等
保留兩位小數,四捨五入:a=a.divide(b).setScale(2,
BigDecimal.ROUND_HALF_UP);
大量方法建議自查api文檔。

③ 編寫程序:用整數1-12依次表示1-12月,由鍵盤輸入一個月份數,輸出對應的季節。

C++語言
#include<iostream>
using namespace std;
int jijie(int i){
if(i>=3&&i<=5)
cout<<"春季"<<endl;
if(i>=6&&i<=8)
cout<<"夏季"<<endl;
if(i>=9&&i<=11)
cout<<"秋季"<<endl;
if(i=12||i<=2&&i>0)
cout<<"冬季"<<endl;
return 0;
}
int main(){
int n;
cout<<"請輸入你要知道的月份:";
cin>>n;
jijie(n);
return 0;
}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:588
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:884
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:576
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:762
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:679
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1009
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:252
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:110
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:801
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:707