|
|
发表于 3-7-2008 11:52 PM
|
显示全部楼层
第一题
- #include <iostream>
- using namespace std;
- int main()
- {
- int sum, no = 3;
- for ( sum = 0; no != 36; no += 3 )
- sum += no;
- cout << sum;
- return 0;
- }
复制代码
第二题
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int correct = 0,
- guess = 0,
- outcome = 0,
- round;
- srand( time(NULL) );
- for ( round = 0; round <= 11; round++ )
- {
- cout << "Guess Head of Tail\n"
- << "Type 1 For Head, 2 For Tail" << endl;
- cin >> guess;
- outcome = (rand() % 2) + 1;
- if (outcome == guess)
- {
- cout << "Matched!" << endl;
- correct++;
- }
- else
- cout << "Sorry" << endl;
- }
- cout << correct << endl;
- return 0;
- }
复制代码 |
|