4.函数create从键盘输入整数序列,以输入0为结束。按输入顺序建立单向链表并返回表头。
struct node{int data; node * next;};
node * create()
{
node *head, *p, *q; p = new node; head = p; cin>>p->data;
while( p->data != 0 ) {
q = p;
p = new node ; q->next = p; cin>>p->data; }
if (head == p) head = NULL;
else q->next = p ; if (head == NULL) delete p ; return head; }
5.以下程序求方程的全部整数解:
3x + 2y - 7z = 5 ( 0 ≤ x, y, z ≤ 100 )
#includevoid main() { int x, y, z ;
for( x=0; x<=100; x++ ) for( y=0; y<=100; y++ ) { if( ( z=3*x+2*y-5 ) % 7 )
break ;
//求出z的值
s=s+(1.0/(n*n*n) ;
if( z<=100&&z>=0 ) //检查z的范围
cout << \ } }
三、程序设计
1. 编写函数输出以下形状的图形,其中构成图形的数字和输出的行数通过参数传送。
1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4
#includevoid main() {
int i,n;
for (i=0;i<5; i++){ for (n=0;n<2*i-1;n++){ cout<
cout<2. 请编程序,输入两个正整数啊a和b(a
the factors of 6 : 2 3
the factors of 7 : no factor
the factors of 8 : 2 4
#include using namespace std; void printFactor(int i); void main() {
int numA,numB;
cout<
cin>>numA>>numB;
for (int i=numA;i<=numB;i++)
{
printFactor(i);
} }
void printFactor(int i) {
cout<
for (int k=2;k
if (i%k==0) {
fact[n]=k; n++; } }
if (n==0)
{
cout<
} else {