本篇文章给大家谈谈c语言如何设置重复提问,以及c语言如何设置重复提问条件对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
1、怎样让c语言程序重复执行?2、C语言写入重复问题3、C语言的重复定义问题4、c语言问题,我想让这个while语句输出的时候只重复一遍那句话,怎么弄?5、在C语言中 如何编写一个重复语句?
怎样让c语言程序重复执行?
例如:
#includestdio.h
intmain(void)
{
charc;
c=getchar();
while(c!=”)//输入空格退出
{
printf(“%c”,c);//这里改成你需要的那个函数做相应的工作就可以了
c=getchar();
}
return0;
}
扩展资料
C语言循环控制语句
#includestdio.h
intmain(){
inta;
/*forloopexecution*/
for(a=10;a20;a=a+1)
{
printf(“valueofa:%d\n”,a);
}
return0;
}
C编程语言中do…while循环的语法是-
do{
statement(s);
}while(condition);
C语言写入重复问题
遍历你设计的学生信息链表,如果发现相同学号提示,并让用户重新输入,我下面的网盘有几个学生管理系统,你可以试试修改一下!修改后的代码在:
其中相关代码如下:student*creat(FILE*fp)//建立链表函数{student*phead=NULL;student*ptail,*p;student*ptemp;intindex=1,num;info.count=0;ptail=p=(student*)malloc(sizeof(student));printf(“依次输入学生学号(回车),姓名(回车),成绩(回车):\n(当输入的学号为“0”时结束输入)\n”);fprintf(fp,”依次输入学生学号(回车),姓名(回车),成绩(回车):\n(当输入的学号为“0”时结束输入)\n”);printf(“学号(回车):”);scanf(“%d”,p-num);if(0!=p-num){printf(“姓名(回车):”);scanf(“%s”,p-name);p-tot=0;for(inttemp=0;tempscore[temp]);p-tot+=p-score[temp];}p-arv=p-tot/info.Class_M;}while(p-num!=0){info.count++;if(info.count==1)//第一条记录为头记录phead=p;//设置第一条记录为头记录elseptail-pnext=p;ptail=p;p=(student*)malloc(sizeof(student));if(phead!=NULL)//判断是不是为空记录{num=-1;while(num==-1){printf(“学号(回车):”);scanf(“%d”,p-num);num=1;index=1;ptemp=phead;do{if(p-num==ptemp-num)num=-1;ptemp=ptemp-pnext;index++;}while(indexnum){printf(“姓名(回车):”);scanf(“%s”,p-name);p-tot=0;for(inttemp=0;tempscore[temp]);p-tot+=p-score[temp];}p-arv=p-tot/info.Class_M;}}ptail-pnext=NULL;//设置尾记录指向空地址if(0==info.count)info.pcurr=NULL;elseinfo.pcurr=ptail;free(p);returnphead;}////////////////////////////////////////////////////////////student*appen(FILE*fp,student*phead)//追加记录函数{student*p;student*ptemp;ptemp=phead;intindex=1,num;printf(“追加一个成员\n”);fprintf(fp,”追加一个成员\n”);p=(student*)malloc(sizeof(student));printf(“学号(回车):”);scanf(“%d”,p-num);printf(“姓名(回车):”);scanf(“%s”,p-name);p-tot=0;for(inttemp=0;tempscore[temp]);p-tot+=p-score[temp];}p-arv=p-tot/info.Class_M;getchar();if(phead!=NULL)//判断是不是为空记录{do{if(p-num==ptemp-num)num=-1;if(0==info.count)info.pcurr=NULL;elseinfo.pcurr=ptemp;ptemp=ptemp-pnext;index++;}while(ptemp!=NULL);if(-1==num){printf(“追加一个成员失败,因为学号%d已经存在!\n”,p-num);fprintf(fp,”追加一个成员失败,因为学号%d已经存在!\n”,p-num);free(p);returnphead;}if(0==p-num){printf(“追加一个成员失败,因为学号不能为0!\n”);fprintf(fp,”追加一个成员失败,因为学号不能为0!\n”);free(p);returnphead;}p-pnext=NULL;info.pcurr-pnext=p;info.count++;info.pcurr=p;returnphead;}else{if(0==p-num){printf(“追加一个成员失败,因为学号不能为0!\n”);fprintf(fp,”追加一个成员失败,因为学号不能为0!\n”);free(p);returnphead;}p-pnext=NULL;info.count++;info.pcurr=phead=p;returnphead;}}////////////////////////////////////////////////////////////student*insert(FILE*fp,student*phead)//在当前记录后插入一个记录函数{student*p;student*ptemp;ptemp=phead;intindex=1,num;printf(“插入一个成员\n”);fprintf(fp,”插入一个成员\n”);p=(student*)malloc(sizeof(student));printf(“学号(回车):”);scanf(“%d”,p-num);printf(“姓名(回车):”);scanf(“%s”,p-name);p-tot=0;for(inttemp=0;tempscore[temp]);p-tot+=p-score[temp];}p-arv=p-tot/info.Class_M;getchar();if(phead!=NULL)//判断是不是为空记录{do{if(p-num==ptemp-num)num=-1;ptemp=ptemp-pnext;index++;}while(ptemp!=NULL);if(-1==num){printf(“插入一个成员失败,因为学号%d已经存在!\n”,p-num);fprintf(fp,”插入一个成员失败,因为学号%d已经存在!\n”,p-num);free(p);returnphead;}if(0==p-num){printf(“插入一个成员失败,因为学号不能为0!\n”);fprintf(fp,”插入一个成员失败,因为学号不能为0!\n”);free(p);returnphead;}p-pnext=info.pcurr-pnext;info.pcurr-pnext=p;info.count++;info.pcurr=p;returnphead;}else{if(0==p-num){printf(“插入一个成员失败,因为学号不能为0!\n”);fprintf(fp,”插入一个成员失败,因为学号不能为0!\n”);free(p);returnphead;}p-pnext=NULL;info.count++;info.pcurr=phead=p;returnphead;}}
C语言的重复定义问题
别把F_Define.c和Data_Define.c文件加入到工程中,应当就编译链接了
或者把这两个定义改为.h扩展名,它们不会生成obj文件,就没问题了
c语言问题,我想让这个while语句输出的时候只重复一遍那句话,怎么弄?
第一种方法:
在if(z==’y’)前面,增加一句:
getchar();
第二种方法:
把z改为整型数,下面的语句进行修改:
(1)char z;改为:int z;
(2)printf语句改为:
printf(“是否要开平方。是输入1,否输入2″,);
三、scanf语句改为:
scanf(“%d”,z)
四、if语句改为:if(z==1)
在C语言中 如何编写一个重复语句?
#include stdio.h
void print_smile(int times)
{
while (times–) {
printf(“Smile!”);
}
printf(“\n”);
}
int main(int argc, char* argv[])
{
print_smile(3);
print_smile(2);
print_smile(1);
return 0;
}
关于c语言如何设置重复提问和c语言如何设置重复提问条件的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。