next; while(p!=NULL) { x=p->data*n; q=("/> next; while(p!=NULL) { x=p->data*n; q=("/>
首页 N的阶乘

N的阶乘

举报
开通vip

N的阶乘N的阶乘 #include "stdlib.h" #include "stdio.h" struct node { long data; struct node *next; }; void fun(struct node *head1,long n,struct node *head) { struct node *p,*q,*r; long x; r=head; if(n!=0) { p=head1->next; while(p!=NULL) { x=p->data*n; q=(...

N的阶乘
N的阶乘 #include "stdlib.h" #include "stdio.h" struct node { long data; struct node *next; }; void fun(struct node *head1,long n,struct node *head) { struct node *p,*q,*r; long x; r=head; if(n!=0) { p=head1->next; while(p!=NULL) { x=p->data*n; q=(struct node *)malloc(sizeof(struct node)); q->data=x; r->next=q; r=q; p=p->next; } r->next=NULL; p=head->next; while(p->next!=NULL) { x=p->data+p->next->data*10; p->data=x%10; p->next->data=x/10; p=p->next; } x=p->data; while(x!=0) { p->data=x%10; q=(struct node *)malloc(sizeof(struct node)); q->data=x/10; if(q->data!=0) {p->next=q; p=q; } x=q->data; } p->next=NULL; /* p=head->next; while(p!=NULL) { printf("%d",p->data); p=p->next; } printf("\n"); */ fun(head,n-1,head1); } else return; } struct node *fun1(long n) { struct node *head,*r,*p; long x; head=(struct node *)malloc(sizeof(struct node)); r=head; while(n) {x=n%10; p=(struct node *)malloc(sizeof(struct node)); p->data=x; r->next=p; r=p; n=n/10; } r->next=NULL; return(head); } void main() { struct node *h,*head1,*p; long n,t=0; scanf("%ld",&n); getchar(); h=(struct node *)malloc(sizeof(struct node)); head1=fun1(n); /*p=head1->next ; while(p!=NULL) { printf("%ld",p->data); p=p->next; } getchar();*/ fun(head1,n-1,h); p=head1->next; while(p!=NULL) { printf("%ld",p->data); p=p->next; } p=head1->next; while(p->data==0&&p!=NULL) { t++; p=p->next ; } printf("*************************"); printf("\nt=%d",t); }
本文档为【N的阶乘】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_531654
暂无简介~
格式:doc
大小:15KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-09-26
浏览量:23