close
//需#include iostream,iomanip using namespace std; int main(int argc, char** argv) { double total,sell; while(1) { cout<< "Enter sales in dollars(-1 to end):"<<endl; cin >>sell; if(sell == -1) break; total=(sell*0.09)+200; cout<<"Salary is:$"<<fixed<<setprecision(2)<<total<<endl; } return 0; }
//需#include iostream,iomanip using namespace std; int main(int argc, char** argv) { int hourwork; double rate; while(1) { double total; cout<<"Enter hours worked(-1 to end) :"<<endl; cin >>hourwork; if(hourwork==-1) { break; } cout<<"Enter hourly rate of the employee($00.00):"<<endl; cin >>rate; if(hourwork>40) { total = (hourwork-40)*1.5*rate+40*rate; cout<<"Salary is $"<<fixed<<setprecision(2)<<total<<endl; } if(hourwork<=40) { total = 40*rate; cout<<"Salary is $"<<fixed<<setprecision(2)<<total<<endl; } } return 0; }
//需#include iostream,iomanip using namespace std; int main(int argc, char** argv) { int number; int temp; int n1,n2,n3,n4; cout<< "Enter a four-digit number :"<<endl; cin >>number; n1=number/1000; n2=number%1000/100; n3=number%1000%100/10; n4=number%10; //每位+7 n1+=7; n2+=7; n3+=7; n4+=7; //此數除10取餘數 為新數 if(n1>10) { n1%=10; } if(n2>10) { n2%=10; } if(n3>10) { n3%=10; } if(n4>10) { n4%=10; } //cout<<"Encrypted number is "<<temp<<endl; //交換 //1234 //3412 temp = n4*100+n1*10+n2*1; cout<<"Encrypted number is "<<temp<<endl; //還原 temp=0; cout<<"Enter an encry number: "<<endl; cin>>temp; n3=temp/1000; n4=temp%1000/100; n1=temp%1000%100/10; n2=temp%10; if(n3-7<0) { n3 = n3+10 -7; } else { n3=n3-7; } if(n4-7<0) { n4 = n4+10 -7; } else { n4=n4-7; } if(n2-7<0) { n2 = n2+10 -7; } else { n2=n2-7; } if(n1-7<0) { n1 = n1+10 -7; } else { n1=n1-7; } cout<<"Decrypted number is "<<(n1*1000)+(n2*100)+(n3*10)+n4; return 0; }
4.
//需#include iostream using namespace std; int main(int argc, char** argv) { int n1,n2,n3; int number=100; while(number<=999) { n1=number/100; n2=number%100/10; n3=number%10; if(number == ((n1*n1*n1)+(n2*n2*n2)+(n3*n3*n3))) { cout<<number<<"是水仙花數"<<endl; } number +=1; } return 0; }
第五題就不提供解法了 有興趣自己摸索吧 XD ((其實是上面在1.5小時內寫完就很頭大了
第三題我提供那個"破"解法 希望諒解 我直接把4位數的首位給砍了
以上都有成功執行,記得要include 標頭檔~ 因為痞克幫會把它吃掉只好沒打出來..
全站熱搜
留言列表