Ⅰ c语言中的清屏有什么作用那
C语言中的清屏的作用为:清除屏幕输出。
调用清屏时,屏幕上的所有输出都将被清除,这相当于为软件重新提供了画布以自由输出。
屏幕清除通常用于以下情况:
1、当最后一个功能的执行完成时,输出不再重要,并且需要显示新的内容或菜单。
2、对于加密,例如某些记忆游戏,在显示几秒钟后,清除所有输出。
3、要显示大部分关键数据,为了避免以前的打印权限信息的影响,请执行屏幕清除操作。
屏幕清除通常使用C语言“system("cls")”来完成。
(1)c语言清包扩展阅读:
clrscr函数是C语言的清屏功能,用于清除屏幕上的输出,而clrscr是clear screen的缩写。 Clrscr不是C语言的标准库函数,而是TC平台独有的函数,其他编译器无法使用。
使用系统(CLS),可以在DOS屏幕中达到清除屏幕的效果。 系统函数已包含在标准C库中,并且通过命令进行系统调用。 函数原型:int system(char *command); 参数:字符类型命令功能:发出DOS命令。
Ⅱ C语言:背包问题(数据结构)
详细程序代码如下:
用VC6.0编译.保存代码时,以.C为后缀名
下面是一组测试数据:
请输入背包能容纳的最大重量:20
请输入物品个数:10
请输入每一个物品的重量和价值:1,11,2,22, 3,33.....10,100
结果是正确的.
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#define NUMBER 20/*最大物品数量*/
#define TRUE 1
#define FALSE 0
struct Record/*本结构体用于保存每一次结果*/
{
int totalWeight;/*本次结果的总价值*/
int goods[NUMBER];/*本次结果对应的下标*/
struct Record *next;
};
struct Record *headLink;
struct Record result;
int stack[NUMBER];
int top;
int weight[NUMBER];/*保存物品重量的数组*/
int value[NUMBER];/*保存对应(下标相同)物品的价值*/
int knapproblen(int n,int maxweight,int weight[]);
void CreateHeadLink(void);
struct Record *MallocNode(void);
void InsertOneNode(struct Record *t);
void GetResult(void);
void ShowResult(void);
void main()
{
int n,i;
int maxWeight;/*背包能容纳的最大重量*/
printf("请输入背包能容纳的最大重量:\n");
scanf("%d",&maxWeight);
printf("请输入物品个数:\n");
scanf("%d",&n);
printf("请输入每一个物品的重量和价值:\n");
for(i=0;i<n;i++)
{
printf("请输入第%d个物品重量\n",i+1);
scanf("%d",&(weight[i]));
printf("请输入第%d个物品价值\n",i+1);
scanf("%d",&(value[i]));
}
if(knapproblen(n,maxWeight,weight)==TRUE)/*调用背包处理函数,如果成功就输出“答案”*/
{
GetResult();/*遍历链表,查找最佳的结果*/
ShowResult();/*显示结果*/
}
free(headLink);
getch();
}
/*调用背包处理函数*/
int knapproblen(int n,int maxweight,int weight[])
{
struct Record *p;
int i=1,j;
int tempTop=0;
top=0;/*先赋栈指针为0*/
CreateHeadLink();/*先建立链头*/
while((maxweight>0)&&(i<=n))/*当还可以装下物品,且物品没有用完时*/
{
if((maxweight-weight[i]==0)||(maxweight-weight[i]>0)&&(i<n))/*正好装完物品或还能容纳物品且物品没有用完时*/
{
stack[++top]=i;/*把对应物品的处标保存到栈中*/
p=MallocNode();/*每一次得到一个结果后,就将该结果保存到链表中*/
for(tempTop=top,j=0;tempTop>0;tempTop--,j++)
{
p->totalWeight+=value[stack[tempTop]];/*得到本次结果的总价值*/
p->goods[j]=stack[tempTop];/*得到本次结果对应的物品下标*/
}
InsertOneNode(p);/*加到链表中*/
maxweight=maxweight-weight[i];
}
if(maxweight==0)/*能装入包中*/
{
return TRUE;
}
else if((i==n)&&(top>0))/*继续测试*/
{
i=stack[top];
top=top-1;
maxweight=maxweight+weight[i];
}
i++;
}
return FALSE;
}
/************************************
函数功能:建立链表表头
************************************/
void CreateHeadLink(void)
{
struct Record *p;
p=(struct Record*)malloc(sizeof(struct Record));
headLink=p;
p->next=NULL;
}
/************************************
函数功能:申请一个新结点,并将其初始化
************************************/
struct Record *MallocNode(void)
{
struct Record *p;
int i;
p=(struct Record*)malloc(sizeof(struct Record));
if(p==NULL)
return NULL;
p->totalWeight=0;/*初始化总价值为0*/
for(i=0;i<NUMBER;i++)
p->goods[i]=-1;/*初始化下标为-1,即无效*/
p->next=NULL;
return p;
}
/************************************
函数功能:在链表的结尾处增加一个结点
************************************/
void InsertOneNode(struct Record *t)
{
struct Record *p;
p=headLink;
while(p->next)
{
p=p->next;
}
p->next=t;
}
/************************************
函数功能:遍历链表,找总价值最大的结点保存到
result中
************************************/
void GetResult(void)
{
struct Record *p;
int i;
result.totalWeight=headLink->next->totalWeight;/*先将第一个结点当作"最佳"结果*/
for(i=0;i<NUMBER;i++)
{
if(headLink->next->goods[i]==-1)
break;
result.goods[i]=headLink->next->goods[i];
}
p=headLink->next->next;
while(p)/*查找最佳结果*/
{
if(p->totalWeight>result.totalWeight)/*如果发现p点价值比当前结果还大,则将p又作为最佳结果*/
{
result.totalWeight=p->totalWeight;
for(i=0;i<NUMBER;i++)
result.goods[i]=-1;
for(i=0;i<NUMBER;i++)
{
if(p->goods[i]==-1)
break;
result.goods[i]=p->goods[i];
}
}
p=p->next;
}
}
/***************************
显示最佳结果
*******************************/
void ShowResult(void)
{
int i;
printf("最佳装载如下:\n");
for(i=0;i<NUMBER;i++)
{
if(result.goods[i]==-1)
break;
printf("weight[%d]=%d\tvalue[%d]=%d\t",result.goods[i],weight[result.goods[i]],result.goods[i],value[result.goods[i]]);
if((i+1)%2==0)
printf("\n");
}
printf("\n总价值是:\n%d",result.totalWeight);
}
Ⅲ c语言清屏命令是,要在哪输入才能清掉运行完的屏幕,截图详细
在程序退出前,system("clear");
Ⅳ C语言都包括几部分
二级所有科目的考试仍包括笔试和上机考试两部分。二级c笔试时间由120分钟
三级网络技术优秀证书
改为90分钟,上机时间由60分钟改为90分钟。
Ⅳ c语言字符串清空函数
字符串函数<string.h>
在头文件<string.h>中定义了两组字符串函数。第一组函数的名字以str开头;第二组函数的名字以mem开头。只有函数memmove对重叠对象间的拷贝进行了定义,而其他函数都未定义。比较类函数将其变量视为unsigned char类型的数组。
1.strcpy
#include <string.h>
char *strcpy(char *str1, const char *str2);
把字符串str2(包括'