栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

自学C语言-视频-张鹏伟-1:50:39

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

自学C语言-视频-张鹏伟-1:50:39

磕磕绊绊终于把这个完成了↓↓↓

有一个最大的疑问:为何在函数中定义指针数组需要static?

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include

#define PASSWORD " "

char *s_gets(char *p,int n);
short checkpassword();
long factorial(int n);
long factorials(int n);
long *long_p_num(int n);
char **char_p_num(int n);
short searchnumber(short n,char **pi);
void shownumber(char *p);

int main()
{
	
	if(!checkpassword())
		exit(1);
	
	int num=0;
	short index=0;
	long *ipnum=NULL;
	char **cpnum=NULL;
	
	fputs("Input the number:",stdout);
	scanf("%d",&num);//待补充判断循环
	while(getchar()!=10);
	printf("%d的阶乘是:%ld.n",num,factorial(num));
	printf("%d的递减阶乘和是:%ld.n",num,factorials(num));
	
	ipnum=long_p_num(num);
	cpnum=char_p_num(num);
	fputs("显示整型数组:{",stdout);
	for(int i=0;i0;
		chance--,printf("Please input the password,(%d chance left)nPassword:",chance))
	{
		if(s_gets(input,5)&&!strcmp(input,PASSWORD))
		{
			fputs("Right!!!n",stdout);
			return 1;
		}
		else
			fputs("Wrong!Again!n",stdout);
		if((chance)==1)//是否可以改良掉这段代码?
			break;
	}
	fputs("No chance left!ProgramOver!n",stdout);
return 0;}

long factorial(int n)//计算阶乘
{
	long sum;
	for(sum=1;n>0;n--)
		sum*=n;
return sum;}

long factorials(int n)//计算递减阶乘和
{
	long sums;
	for(sums=0;n>0;n--)
		sums+=factorial(n);
return sums;}

long *long_p_num(int n)//整数数组存储
{
	long *p_num=(long *)calloc(n,sizeof(long));
	for(int i=0,i1=n;i0;lenth++)
			copy/=10;
		pctemp[i]=(char *)calloc(lenth+1,sizeof(char));		
		_itoa(itemp,pctemp[i],10);
	}
return pctemp;}

short searchnumber(short n,char **pi)
{
	short index=0;
	char ctemp[10]={0};
	for(fputs("Input the number you wanna show(NothingQuit).nnumber:",stdout);
		!index;
		fputs("Couldn't found the number,try another one(NothingQuit).nnumber:",stdout),index=0)
	{
		if(!s_gets(ctemp,10))
			return 0;
		for(;index 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/509965.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号