回复 4楼 beyondyf
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct num)
struct num
{
int s;
struct num * next;
};
int main()
{
struct num *p, *q1, * q2, *head;
int i, n;
printf("Please input n:");
scanf("%d", &n);
head = q1 = (struct num * ) malloc (LEN);
q1 -> s = 1;
q2 = (struct num * ) malloc (LEN);
q1 -> next = q2;
q2 -> s = 1;
p = (struct num * ) malloc (LEN);
q2 -> next = p;
for (i = 2; i <= n; i++)
{
p -> s = 3 * (q1 -> s) + 2 * (q2 -> s);
p = (struct num * ) malloc (LEN);
q2 -> next -> next = p;
q2 = q2 -> next;
q1 = q1 -> next;
}
p -> next = NULL;
for (i = 0; i <= n; i++)
{
printf("%d \n", head -> s);
head = head -> next;
}
return 0;
}
[
本帖最后由 有容就大 于 2011-12-22 22:47 编辑 ]