C语言程序,帮忙解释一下,急...流程图帮忙画下

1.题目:反向输出一个链表#include<stdlib.h>#include<stdio.h>structlist{intdata;structlist*next;};... 1.题目:反向输出一个链表
#include <stdlib.h>
#include <stdio.h>
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
void main()
{ link ptr,head,tail;
int num,i;
tail=(link)malloc(sizeof(node));
tail->next=NULL;
ptr=tail;
printf("\nplease input 5 data==>\n");
for(i=0;i<=4;i++)
{
scanf("%d",&num);
ptr->data=num;
head=(link)malloc(sizeof(node));
head->next=ptr;
ptr=head;
}
ptr=ptr->next;
while(ptr!=NULL)
{ printf("The value is ==>%d\n",ptr->data);
ptr=ptr->next;
}}
2.时间函数举例4,一个猜数游戏,判断一个人反应快慢
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
void main()
{char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{if(guess>i)
{printf("please input a little smaller.\n");
scanf("%d",&guess);}
else
{printf("please input a little bigger.\n");
scanf("%d",&guess);}
}
if((c=getch())=='y');
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");

}
3.计算字符串中子串出现的次数
#include <string.h>
#include <stdio.h>
void main()
{ char str1[20],str2[20],*p1,*p2;
int sum=0;
printf("please input two strings\n");
scanf("%s%s",str1,str2);
p1=str1;p2=str2;
while(*p1!='\0')
{
if(*p1==*p2)
{while(*p1==*p2&&*p2!='\0')
{p1++;
p2++;}
}
else
p1++;
if(*p2=='\0')
sum++;
p2=str2;
}
printf("%d",sum);
getch();
}
4.有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
# include <stdio.h>
void main()
{
int number[20],n,m,i;
printf("the total numbers is:");
scanf("%d",&n);
printf("back m:");
scanf("%d",&m);
for(i=0;i<n-1;i++)
scanf("%d,",&number[i]);
scanf("%d",&number[n-1]);
move(number,n,m);
for(i=0;i<n-1;i++)
printf("%d,",number[i]);
printf("%d",number[n-1]);
}
move(array,n,m)
int n,m,array[20];
{
int *p,array_end;
array_end=*(array+n-1);
for(p=array+n-1;p>array;p--)
*p=*(p-1);
*array=array_end;
m--;
if(m>0) move(array,n,m);
}
我的邮箱bao19911112@qq.com程序图可以画在word上,急用...麻烦大家帮忙下...
展开
 我来答
魔法师00可可
推荐于2016-11-30 · TA获得超过1660个赞
知道大有可为答主
回答量:726
采纳率:100%
帮助的人:953万
展开全部
1.题目:反向输出一个链表
#include <stdlib.h>
#include <stdio.h>
struct list
{ int data;
struct list *next;
};//结构体定义
typedef struct list node;
typedef node *link;
void main()
{ link ptr,head,tail;
int num,i;
tail=(link)malloc(sizeof(node));//分配指针空间
tail->next=NULL;
ptr=tail;
printf("\nplease input 5 data==>\n");
for(i=0;i<=4;i++)//读入5组数据
{
scanf("%d",&num);
ptr->data=num;
head=(link)malloc(sizeof(node));
head->next=ptr;
ptr=head;
}
ptr=ptr->next;
while(ptr!=NULL)//输出刚才输入的值
{ printf("The value is ==>%d\n",ptr->data);
ptr=ptr->next;
}}
2.时间函数举例4,一个猜数游戏,判断一个人反应快慢
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
void main()
{char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;//100以内的随机数
printf("\nplease input number you guess:\n");
start=clock();//从你开始猜第一个数计时
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)//猜不对给出提示,并让你接着猜
{if(guess>i)
{printf("please input a little smaller.\n");
scanf("%d",&guess);}
else
{printf("please input a little bigger.\n");
scanf("%d",&guess);}
}
if((c=getch())=='y');如果什么时候没提示了,说明你猜对了。这时要按个‘y’才能停止计时
end=clock();
b=time(NULL);
//输出你的结果
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
//判断你所属于的级别
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");

}
3.计算字符串中子串出现的次数
#include <string.h>
#include <stdio.h>
void main()
{ char str1[20],str2[20],*p1,*p2;
int sum=0;
printf("please input two strings\n");//读入两个字符串
scanf("%s%s",str1,str2);
p1=str1;p2=str2;//
while(*p1!='\0')//字符串1不结束时,循环
{
if(*p1==*p2)//字符串1、2中字符相同,指针同时向后移一位
{while(*p1==*p2&&*p2!='\0')
{p1++;
p2++;}
}
else
p1++;
if(*p2=='\0')//字符串1中出现了和字符串2中相同的字符串
sum++;//计数加一
p2=str2;//p2重新移向数组头
}
printf("%d",sum);//输出结果
getch();
}
4.有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
# include <stdio.h>
void main()
{
int number[20],n,m,i;
printf("the total numbers is:");//要输入数据的个数
scanf("%d",&n);
printf("back m:");//移动的位数
scanf("%d",&m);
for(i=0;i<n-1;i++)//输入n个数据
scanf("%d,",&number[i]);
scanf("%d",&number[n-1]);
move(number,n,m);//调用子函数
for(i=0;i<n-1;i++)//移动后的结果
printf("%d,",number[i]);
printf("%d",number[n-1]);
}
move(array,n,m)
int n,m,array[20];
{
int *p,array_end;
array_end=*(array+n-1);
for(p=array+n-1;p>array;p--)//所有数据向后移动一位
*p=*(p-1);
*array=array_end;
m--;
if(m>0) move(array,n,m);//判读是否移动完成
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式