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

📄 质因子.c

📁 这里面包含了大量的数据结构的常用算法,大家可一看看有不有对自己有用的东西
💻 C
字号:
#include <stdio.h> 
#include <stdlib.h>

struct node
{
	long factorarray;
	struct node *next;
};
struct node *head,*q,*p;

void factoring(long n) 
{ 
long i; 
for(i=2; i<=n/2; i++)
{ 
	if(n%i==0)
	{  
		q=(struct node*)malloc(sizeof(struct node));
		q->factorarray=i;
		q->next=NULL;
		if(head==NULL)
		{
			head=q;
			p=q;
		}
		else
		{
			p->next=q;
			p=q;
		} 
	} 
} 
}

void deletes()
{
	while(head!=NULL)
	{
		p=head;
		head=p->next;
		free(p);
	}
}

void main() 
{ 
long num; 
head=NULL;
printf("Please input the number you want to find factors: "); 
while(scanf("%ld", &num)) { 
printf("The factors of the number %ld is: \n", num); 
factoring(num); 
p=head;
while(p!=0) 
{
printf("* %ld", p->factorarray);
p=p->next;
} 
printf("\nPlear input the number you want to find factors: ");
deletes(); 
} 
} 

⌨️ 快捷键说明

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