※ [本文轉錄自 NTUCivilSA 看板]
作者: jtouch (Woodstock) 看板: NTUCivilSA
標題: [公告] 計程期中考題目
時間: Mon May 2 17:32:27 2005
[Q1] (15%) Please write down the output of the following codes
(a) (5%)
#include<iostream.h>
void main() {
int i,j;
cout<<"start here!\n";
for(i=0;i<7; i++)
for(j=i;j<10; j++, i++)
cout<< ++i<<j++;
j++;i++;
}
(b) (5%)
#include<iostream.h>
void main() {
int i,j;
cout<<"start here!\n";
do
{
if(i=1) cout<<"b";
for(j=i;j<10; ++j,i++)
cout<< i++<<j++;
if(i++>8) break;
}while(2);
}
(c) (5%)
#include <iostream>
#include <iomanip>
using namespace std;
long nextFib();
static long last = 1; // 這是指定last為全區(global)變數的指令
static long lastButOne = 3;// 這是指定lastButOne為全區(global)變數的指令
int main()
{
cout << endl << "The output is:" << endl;
for(int i = 0 ; i < 10 ; i++)
{
if(i % 5 == 0)
cout << endl;
cout << nextFib();
}
cout << endl;
return 0;
}
long nextFib()
{
long next = last + lastButOne;
lastButOne = last;
last = next;
return last;
}
[Q2] (20 point) What is the output of the following program?
#include <iostream.h>
#define Y 4
#define X Y/3 + Y*3
void main()
{
int trick(int&, int, int&);
int i, j, m = X*Y, n = Y*X, k=X, var1;
float var2;
cout<<"Start here:\n ";
var1 = m/n; cout<<"line1:"<< var1<<endl;
var2 = trick(m,k,n);
cout<<"line2:"<<var2<< m<< n<< k <<endl;
var2 = trick(m,k,n);
cout<<"line3:"<<var2<< m<< n<< k <<endl;
for(i=0; i<10; ++i) {
if(i==3) {
cout<<"continue\n";
continue;
}
j=0;
for(j; j<i; j++) {
m = j%2;
if(m) {
if (m = -1) cout<<"NG!";
cout<<"break\n";
break;
}
else
{ if (m = 0) cout<<"OOPS!";
cout<<"i=" << i++ <<", j="<< j<< endl;
}
}
}
cout<<"i+j="<< i+j <<endl;
}
int trick(int &x, int y, int & z)
{
int w=5;
w=y;y=x;x=w;
return(++z);
}
[Q3] [15 Points]
寫程式:列印由1,2,3,4 這四個數字組成的所有可能的四位數,
並算出總共可有多少個數? (如1111, 1234, 2222, 2121, 3232, 4141, …..)
[Q4] (20point)
Write a C++ program to compute
3! 5! 5! (2n+1)! (2n+1)!
- X - X - X ... X ---- X ----
4 4 6 2n 2n+2
After allowing the user to input the value of n,
the program should report the computed result.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.12.167
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.12.167