⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.c

📁 《数据结构-使用C语言》第三版
💻 C
字号:
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>

typedef long DataType;

#include "DLNode.h"

int main()
{
	DLNode *head, *p;
	void Multiply(DLNode *head, DataType x);
	long n, i, j, t;
	while(scanf("%ld",&n)!=EOF)
	{
		ListInitiate(&head);
		ListInsert(head, 0, 1);
		for(i=1;i<=n;i++)
		{
			Multiply(head, i);
		}
		
		p=head->next;
		printf("%d ",p->data);
		p=p->next;
		while(p!=head)
		{
			j=0;
			t=p->data;
			while(t!=0)    //中间不足4位数的用0补充 
			{
				t/=10;
				j++;
			}
			for(i=0;i<3-j;i++)printf("0");
			if(j!=0)printf("%d ",p->data);
			else printf(" ");   //结果每四位用空格分开 
			p=p->next;
		}
		printf("\n");
	}
	return 0;
}

void Multiply(DLNode *head, DataType x)
{
	DLNode *p;
	
	p=head->prior;
	while(p!=head)
	{
		p->data*=x;
		p=p->prior;
	}
	p=head->prior;
	while(p!=head)
	{
		if(p->data<999)
		{
			p=p->prior;
			continue;
		}
		if(p->prior!=head)
		{
			p->prior->data+=p->data/1000;
			p->data%=1000;
			p=p->prior;
		}
		else 
		{
			if(ListInsert(head,0,0)==0)
			{
				printf("error!\n");
				return ;
			}
			p->prior->data+=p->data/1000;
			p->data%=1000;
			p=p->prior;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -