日子的相差如果是要計算年月日,那就掰掰啦;若只計算月日的話,我會在看完筆記後嘗試。另一條就是(看來)要輸入十個數字(0至10),再根據數字輸出對應的英文。我想到的是非常愚蠢的方法,不過只有45分鐘的測試,怎可能寫出我這個笨方法。如果是輸入一個數字,輸出一個英文的話就超簡單啦。以下是代碼:
#include <iostream>
using namespace std;
void main(){
int intNum1;
cout << "Please enter a number (0 to 10): ";
cin >> intNum1;
if(intNum1 == 1){
cout << "one ";
}else if(intNum1 == 2){
cout << "two ";
}else if(intNum1 == 3){
cout << "three ";
}else if(intNum1 == 4){
cout << "four ";
}else if(intNum1 == 5){
cout << "five ";
}else if(intNum1 == 6){
cout << "six ";
}else if(intNum1 == 7){
cout << "seven ";
}else if(intNum1 == 8){
cout << "eight ";
}else if(intNum1 == 9){
cout << "nine ";
}else if(intNum1 == 10){
cout << "ten ";
}else if(intNum1 == 0){
cout << "zero ";
}else{
cout << "error ";
}
cout << endl;
system("pause");
}
#include <iostream>
using namespace std;
void main(){
int intDayN, intSum, intSum2;
cout << "Please enter a number(day): ";
cin >> intDayN;
intSum = intDayN / 7;
intSum2 = intDayN % 7;
if((intSum == 1) || (intSum == 0)){
if((intSum2 == 0) || (intSum2 == 1)){
cout << "There is " << intSum << " week and " << intSum2 << " day\n";
}else{
cout << "There is " << intSum << " week and " << intSum2 << " days\n";
}
}else{
if((intSum2 == 0) || (intSum2 == 1)){
cout << "There are " << intSum << " weeks and " << intSum2 << " day\n";
}else{
cout << "There are " << intSum << " weeks and " << intSum2 << " days\n";
}
}
system("pause");
}
#include <iostream>
using namespace std;
void main(){
int intNum, intNum2, intSum;
intSum = 0;
cout << "The equation is 1 ^ 3 + 2 ^ 3 + 3 ^ 3 ... n ^ 3" << endl;
cout << "Please enter a number: ";
cin >> intNum;
for(intNum; intNum >= 0; intNum--){
intSum = intSum + intNum * intNum * intNum;
}
cout << "The sum is: " << intSum << endl;
system("pause");
}
0 件のコメント:
コメントを投稿