c语言编程软件程序设计!!有一个if语句 if( rewind(stdin), 1!=scanf( %d ,&choice) )

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
阅读(285)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'C语言笔记(一)---基本类型、运算符、表达式、分支结构及循环控制、scanf、printf介绍',
blogAbstract:'C语言教程讲义一,C语言概述1,只有32个关键字:auto break case char const continue default do double else enum extern float for goto if int long register return short signed static sizof struct switch typedef union unsigned void volatile whileTurbo C 扩充了11个关键字: asm _cs _ds _es _ss cdecl far hugeinterrupt near pascal2,语法限制不太严格,程序设计自由度大3,C语言允许直接访问物理地址,能进行位(bit)操作,能实现汇编语言的大部分功能,可以直接对硬件进行操作。因此有人把他称为中级语言。',
blogTag:'c语言基础',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:7,
publishTime:5,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'无',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}有一个函数: { x (x&1) y={ 2x-1 (1&=x&10) { 3x-11 (x&=10) 输入x求y,刚开始学,希望大家多多指教_百度知道
有一个函数: { x (x&1) y={ 2x-1 (1&=x&10) { 3x-11 (x&=10) 输入x求y,刚开始学,希望大家多多指教
=x;(x&=10)
y=3x-11;=x&(1&1)
怠舀壁缎撰等刁纶 y=2x-1;(x&lt
提问者采纳
printf(&%f&
else y=3*x-11;
if(x&丝眯弛恍佾喝敷勤
printf(&);
else if(x&lt,&x):\1) y=x;;n&
scanf(&quot,y;y=%f&#92,y);n&int main(){=10) y=2*x-1
其他类似问题
多多指教的相关知识
其他2条回答
)。程序; else if (x& return吹塘摆核肢姑大普 0,程序中可以用if语句来进行分支处理;%d&quot, y); y = fun(x);}int main(){10)
y = 2*x-1; else
y = 3*x-11;输入x;分析;解得y;=1 && x&lt,
scanf(& printf(&n&quot.h&gt:这是一个分段函数;int fun(int x){ int y = 0, &x); if (x& printf(&;1)
y = x:%d&stdio:#include &lt:%d&#92
float func(float x){if(x&1)else if(x&=10)
return 2*x-1;else
return 3*x-11;}//你还是多看书本吧,百度是用来研究学习的,不要什么都依赖于百度知道
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁设计一个简单的C语言程序,要求使用到for或if语句,把要运行的目的也告诉我,急用,麻烦了。_百度知道
设计一个简单的C语言程序,要求使用到for或if语句,把要运行的目的也告诉我,急用,麻烦了。
提问者采纳
scanf(&max)max=a; max=min=a;,&a);
if(a&stdio&#47,i& for(i=0,max,&a);#include &从键盘输入10个整数存入数组,并输出;. ;%d&%d&max=%d min=%d&#92。&#47,找出其中最大和最小值; } printf(&void main(){
int i:1 9 20 2 3 4 5 6 7截池惯课甙酒进素 8max=20 min=1请按任意键继续;;9.h&运行情况. ,a;/}//n& scanf(&min)min=a,&#47,min)
提问者评价
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁C语言中这样的if语句是不是合法的?
C语言中这样的if语句是不是合法的? 100
int a[10],*p,j,N,flag=0; char ch1; j=0; scanf(&%d&,&a[j]); while(flag!=1) {
j++; scanf(&%d&,&a[j]); if(a[j]==0){ printf(&Whether the importation of finished,y or n ?\n&); scanf(&%c\n&,&ch1); if(ch1=='y') scanf(&%d&,&a[j]); else
} } flag=1;
补充:忘了,不是语法有错误,但是上面那个if语句总是不执行,这是完整程序:
#include&stdio.h&void fanxu(int *p,int n){
int i,j,t;
for(i=0,j=n-1;i&n/2;i++,j--)
*(p+i)=*(p+j);
}}main(){ int a[10],*p,j,N,flag=0; char ch1; j=0; scanf(&%d&,&a[j]); while(flag!=1) {
j++; scanf(&%d&,&a[j]); if(a[j]==0){ printf(&Whether the importation of finished,y or n ?\n&); scanf(&%c\n&,&ch1); if(ch1=='y') scanf(&%d&,&a[j]); else
} } flag=1; N=j; fanxu(a,N); p=a; for(p=a;p&a+N;p++) printf(&%d &,*p); printf(&\n&);}
说明:此程序是让输入的数据逆序输出,上面if语句主要是为了控制输入数据到什么时候结束,因为如果直接控制输入的数据怕会重复,以免影响结果,而且输入的数据是没有条件控制的,所以只好用上面的方法控制了,请高手帮我看看为什么此程序是不成功的?谢谢~,问题解决之后再加50分。
补充:是合法的,我想问的是合不合理?刚才说法有错误,如果不合理该怎么解决呢?
补充:两个一同看下吧:
void fanxu(int *p,int n){
int i,j,t;
for(i=0,j=n-1;i&n/2;i++,j--)
*(p+i)=*(p+j);
}}main(){ int a[10],*p,j,N,flag=0; char ch1; j=0; scanf(&%d&,&a[j]); while(flag!=1) {
j++; scanf(&%d&,&a[j]); if(a[j]==0) { printf(&Whether the importation of finished,y or n ?\n&); scanf(&%c&,&ch1); if(ch1=='y') flag=0; else flag=1; } } N=j; fanxu(a,N); p=a; for(p=a;p&a+N;p++) printf(&%d&,*p); printf(&\n&);}
补充:你们先想一下吧,明天给答案也不迟的,时间不早了。。。。
补充:为什么输入0之后不敲回车,直接输入y或n,程序也不能正常运行呢?谢谢~
看了一下你的意思,以下可以满足你的要求(主要是main函数中输入数据的策略修改了,另外加入了一维动态数组技术),你的程序的主要问题在于从键盘上获取单个字符,由于C语言(多数语言)的控制台键盘输入都带有缓冲,要在循环中准确获取字符是比较困难(会将回车等读入,一般用getch、getc等函数)。在下面修改后的程序里避免这个问题。
#include &stdio.h&#include &stdlib.h& //malloc和free需要void fanxu(int *p,int n){ int i,j,t; for(i=0,j=n-1;i&n/2;i++,j--) {
*(p+i)=*(p+j);
*(p+j)=t; }}
main(){ int *a,*p,j,N=0; char ch1; while (N & 1) {
printf(&Enter N=? &);
scanf(&%d&, &N); } a = (int*)malloc(sizeof(int)*N); //动态分配内存 for (j = 0; j & N; j++) scanf(&%d&, &a[j]); N=j; fanxu(a,N); p=a; for(p=a;p&a+N;p++)
printf(&%d &,*p); printf(&\n&); free(a);}
不用这种方法,在原程序基础上可以有什么改进吗?谢谢~
#include &stdio.h&void fanxu(int *p,int n){ int i,j,t; for(i=0,j=n-1;i&n/2;i++,j--) {
*(p+i)=*(p+j);
*(p+j)=t; }}main(){ int a[10],*p,j,N,flag=0; char ch1; j=0; scanf(&%d&,&a[j]); while(flag!=1) {
scanf(&%d&,&a[j]);
if(a[j]==0){
printf(&Whether the importation of finished,y or n ?\n&);
ch1 = getche(); //scanf(&%c\n&,&ch1); 用个这可以
if(ch1=='y')
scanf(&%d&,&a[j]);
} } flag=1; N=j; fanxu(a,N); p=a; for(p=a;p&a+N;p++)
printf(&%d &,*p); printf(&\n&);}
使用scanf(&%c\n&, ch1)会将上次scanf输入的最后一个'\n'读到ch1中,所以你的程序每次都相当于选择了'n'。
但是即使我输入0之后不敲回车,直接输入y结果为什么还是不对呢?谢谢啊~
#include &stdio.h&void fanxu(int *p,int n){ int i,j,t; for(i=0,j=n-1;i&n/2;i++,j--) {
*(p+i)=*(p+j);
*(p+j)=t; }}main(){ int a[10],*p,j,N,flag=0; char ch1; j=0; scanf(&%d&,&a[j]); while(flag!=1) {
scanf(&%d&,&a[j]);
if(a[j]==0){
printf(&Whether the importation of finished,y or n ?\n&);
ch1 = getche();//scanf(&%c\n&,&ch1);
rewind(stdin);
if(ch1=='y')
scanf(&%d&,&a[j]);
} } flag=1; N=j; fanxu(a,N); p=a; for(p=a;p&a+N;p++)
printf(&%d &,*p); printf(&\n&);}
为什么一定要盘缓冲呢?我不敲回车,直接输入为什么会不行呀?
还请帮忙解释一下吧,谢谢~
接收数据是以TAB('\t')、空格或换行(回车)为,你不敲回车(或空格、TAB键)gn ,scanf函数是收不到数据的。
的感言:非常感谢,只是想证实一下,我原来也这样想,高手很厉害啊! 满意答案
合法但不合理!
对,我想问的也就是为什么不合理?
printf(&Whether the importation of finished,y or n ?&);scanf(&%c&,&ch1);
之间加个getchar();就行了,如下面
printf(&Whether the importation of finished,y or n ?&);getchar();scanf(&%c&,&ch1);
这样就可以正常运行了
果然能正常运行了!佩服!这样有什么用意呢?
这样是消除掉上次输入未处理的,如回车或者空格等等
还行再问一下:
如果输入0之后我不输入其他的,直接输入y或者n ,程序为什么还是不能正常运行呢?谢谢~
的感言:非常感谢,以追加悬赏,谢谢啊。。。。
其他回答 (8)
对啊,有什么问题吗
合法的
编译通过
这段程序语法上无错误,逻辑上有错:我觉得第一个scanf中应是&a[0]..另外致命的是while语句无结束条件,一直循环.flag=1应放在最后一个scanf后,并用大括号括起来
语法没问题所以能通过,编译器只能识别语法错误,但逻辑有错误,所以运行结果不正确.
此程序要怎么改才好呢?
但是运行不通过?请帮忙看一下吧,明天给答案也不迟,谢谢~
另外,我看你的意思,if函数中'y'应改为'n'吧
我从while开始:while(flag!=1){j++;scanf(&%d&,&a[j]);if(a[j]==0){printf(~);scanf(&%c&&ch1);if(ch1=='y')flag=1;}}如a[j]=0,则输入y停止
if语句这样用没有问题
但是为什么会不执行?帮忙看下第二个程序吧,谢谢~
if(ch1=='y') 是合法的。
现在的编译器在你定义变量时如果不赋值,会自动赋值的。也就是0而字符型的y肯定是一个值了。。
这两个比较就是对应的ASCII值比较。显然不相等,所以就不执行了
我也不清楚,不过来给你顶一下人气哦!
scanf()使用后 将会有一个回车存入缓存区,我们加一个getchar()是用来消去那个回车,也就是我们常说的“吃回车”
但是我不敲回车,直接输入y或n,为什么还是不能正常运行呢?
将scanf()换成getch()再试一下
改成这个ch1=getch()
不是if出问题哦,是scanf函数出现问题了!
%c这个格式是得一个字符,它就是回车也算是,所以你的程序就出了问题!
你第一个scanf是不是回车啊,这就使得这个回车直接赋给了下面的ch1,不需要再输入了~~
可是为什么还会停呢?这就是scanf(&%c\n&,*&c1); 中的'\n'了,这时就待你的回车了!所以一般不这样写
至于为什么输入的字符还存在,这就是缓冲作用保留下来了!
`
`
修改scanf这句的几个方法:
1。就是在scanf函数的前面加getchar函数,吃掉回车或多余的字符
2。如果你下子输入了很多字符,那getchar不是要很多个来吃,这时就用fflush(stdin),
即在scanf输入这前先清空缓冲区;
3。scanf(& %c&,&c1);
看清楚点,就是在%c 前面多了一空格,也能吃回车;
4。干脆不用scanf了,就用getch(),但注意不能用getchar,它也一样会
5。scanf(& %c\n&) 的回\n去哦,一般scanf不要这样做
6。可能还有,暂时想不出了~~~~
`
`
#include&stdio.h&void fanxu(int *p,int n){int i,j,t;for(i=0,j=n-1;i&n/2;i++,j--){t=*(p+i);*(p+i)=*(p+j);*(p+j)=t;}}main(){int a[10],*p,j,N,flag=0;char ch1;j=0;scanf(&%d&,&a[j]);while(flag!=1){j++;scanf(&%d&,&a[j]);if(a[j]==0){printf(&Whether the importation of finished,y or n ?\n&);scanf(& %c&,&ch1);if(ch1=='y')scanf(&%d&,&a[j]);else}}flag=1;N=j;fanxu(a,N);p=a;for(p=a;p&a+N;p++)printf(&%d &,*p);printf(&\n&);
}
此方法还有一点不是很恰当,就是以前的0没有包含,而楼上的方法是解决了,但是还有一点小小的问题,这个问题是可以忽略的,就是最后一个0没有包含,但前面的包含了,基本来说也算是个成功的程序。
但是现在还有一点不是很清楚,他们都说是加getchar()是接收回车键,或者其它字符,但是如果我不敲回车,直接输入y或者n为什么程序还是不成功呢?能帮忙解释一下吗?
不行哦,getchar是等待一个字符,以回车表示输入结束哦!要不然只会一直等待~~~
用getch()就不用回车了,getche()也一样,不过它的字符有回显在屏幕上的!
自己体会一下这个:
#include &stdio.h&
main(void)
a = getch();
printf(&-%c\n&, a);
a = getche();
printf(&-%c\n&,a);
a= getchar();
printf(&-%c\n&,a);
a = getchar();
/*&----将被回车取代,不用输入*/
printf(&-%d\n&,a); /*
打出那换行符,十进制值*/
return 0;}
等待您来回答
编程领域专家急!!!求一个C语言的源程序,要求有注册,登陆,修改密码这些功能。大概在200行左右_百度知道
急!!!求一个C语言的源程序,要求有注册,登陆,修改密码这些功能。大概在200行左右
而且可以执行通过的,记住哦如果实在没有,一定是在C语言平台上,那就来一个与密码有关种肝摧何诋蛊个曝的源程序也行,谢了
A';a&#39,count)))
printf(&\请正确输入&} &#47:
if((current_user = is_my_user(our_scanf(&您的密码修改失败; i &:%d,u;Z');%d&}}/);
/char repassword[13]; && *p & || isdigit(*p)))
return 0;}printf(&quot.password)==0))
return i + 1;n登陆失败;n你注册姓名是;&#47,首字符为字母;请再次输入注册密码;
printf(&&#92!&)
||(*p &gt,mima2);;}/='注册
case 2;A');Z'
return 1;scanf(&quot:
printf(&printf(&quot:&return 1,repassword)){
printf(&最大13位char like[255];** 完成注册功能 */if(;)
||(p[i] &n你的个性签名;判断首字符是不是字母{
for(i = 0;请输入新密码;= '}void update_password(struct user *ptr_退出) || (p[i] &= '= '1){
return 0;n注册成功;if(i){
i--;fflush(stdin); && *p &lt!(p[i] == &#39:
update_password(our_users.修改密码&}/\/))) /int user_register(struct user *ptr_ i++)
if(;z' && *p &)!&quot!two_password_valid(password!&fflush(stdin),p2)==0)
return 1;\
return 0,这将是您的登陆帐号;a'))) /&#92,u;for(.user_name);},char*p2){if(strcmp(p1;len = strlen(p);}else
printf(&最大18位char password[13]:
exit(1),p[i];}else; && *p &= ')!(length_password(ptr_user[size];);您输入的密码无效;/}printf(&quot:
if(user_register(our_);判断后面字符是否有效
//A'!(isalpha(*p) || *p == '= &#39!; && p[i] &)){
p++:%s&quot,u;0' && *p &完成新旧密码的调换
printf(&quot.h&while(1){
switch(show_menu())
case 1;);\\n3;
}}return 0;
return 0;fflush(stdin);= '#include&)!&** 判断用户名是否有效*/n你的爱好:&quot.sign);判断字符是否有效
return 0,后面必须为字母!&= &#39.注册&0'printf(&}printf(&= '请再次输入新密码;您输入的姓名无效;修改密码
case 4;n你的帐号是,密码应在6-12之间,密码只能包含字母和数字;}else{
printf(&Z'** 密码的有效性验证*/ }void display_user(struct user u){printf(&int is_my_user(struct user *p;l=strlen(p);='}/\}elseprintf(&}else
return 0: &quot.fflush(stdin),mima2[13];gets(password);%d&quot!(length_user_name(ptr_user[size];/
display_user(our_users[current_user - 1])!&n4;);\&#47,u;gets(mima);) || (*p &}/printf(&** 验证用户名长度是否合法*/);='12){
return 0,否则返回0*&#47!&显示菜单int show_menu(){char user_name[19];int length_user_name(char *p){
if(;scanf(&).like).user_name)!&if(len&= '}else{
return 0;%s&printf(&quot,int size){char mima1[13],password);= '注册人数以满!&;).&);printf(&%s&quot.user_name))){
printf(&/printf(&
printf(&printf(&}return 1;#define N 100struct user{int user_/请输入您的帐号;
break!; && p[i] &);printf(&););** 判断用户名是否有效*/
return 0;** 密码长度有效性验证*/char mima[15];}int main(){struct user our_users[N].password)&&is_password_valid(ptr_user[size];&#92!&int is_password_valid(char *p){int i=0;).like); && *p &}if(;int valid_user_name(char *p){int i=0;a&#39.sign);&#92,count))
count++;n登陆成功;//登陆
case 3; p++){
if(:&);请输入注册密码,int size){char password[13];);&#47.h&\) || (*p &
&#47,ptr_user[size];);if(size==N){
puts(&&#47: &n&;\) || (*p &\9'
/z' || (p[i] &z'}printf(&请输入注册姓名;scanf(&gets(repassword);int is_username_valid(char *p){if((*p &gt.user_id=10000+size).登陆&quot,&zhanghu);_&#39!= &#39.user_name)&&valid_user_name(ptr_user[size];a'= 'gets(ptr_user[size],mima2) && length_password(mima1) && is_password_valid(mima1)){
strcpy(ptr_user[i];#include&z'if(,count);/fflush(stdin);n两次输入的密码不一致,int size){size!;if(l&gt:&
}printf(&quot.user_id);if((*p &int current_*int length_password(char *p){= 'A'
}}return 0;i++){
if((zhanghu == p[i],mima1);9'='=');请输入您的密码;),mima1);.h&gt: &= &#39:%s&/);
return 0:%d&
return 1;0'#include&n您的的密码修改成功;\if(two_password_valid(mima1;请输入您的个性签名,size);}else{
strcpy(ptr_user[size];printf(&
p++;n1:&n2;6||len&_&#39,&choice),用户名在1-18之间;n请选择1-4\gets(ptr_user[size].h&\printf(&else
return 0:%s&printf(&i&/ && *p &}/\);char sign[255];;18||l&lt.退出&quot.password))){
printf(&n帐号密码不存在;请输入您的爱好: &int i = is_my_user(ptr_int len = strlen(p);)) &#47,数字或下划线;gets(ptr_user[size];您的编号为;printf(&= 'Z&#39#include&lt!!( (*p &}int two_password_valid(char *p1; && p[i] &='fflush(stdin).user_id)&&(strcmp(mima.;** 如果登陆成功则返回第i+1个用户的信息;int count = 0;for(i=0
提问者评价
已经晚了,如果你在一个半月之前给我就好了,我一定会给你加分,谢了哥们儿!
其他类似问题
按默认排序
其他1条回答
Pass Set Successfully ,sizeof(input));&iostream&/&判断密码文件是否存在 不存在表示未设置过密码 { ifstream fin(infile);}void changepass(){ char pass[PASSLEN];
int n!&} ifstream fin(infile);保存密码的文件s
&#47:&&lt,如果存在就提示; if(temp[0]==0)i++) /
isok=false。#include&;& / cout& ofstream fout(infile););/&& temp[0]=0,否则就OK;fstream&这是接下来你要加的代码了
} system(&/);& if(我有一个C++的运行程序需要输入密码的程序;这个东西用来加密密码s #define infile &; cin&
} if(isok) &#47,密码保存在文件中是加密的;bool exist() &#47:&quot!exist()) /);Please Set New P /密码文件不存在就重新设置密码
{changepass();cout&/Please Input The P
#include&;/&
pass-=PASS;/
if(pass[i];i&&lt。至于注册之类的可以再加上一个文件保存用户名和密码; cin& return 0;这个循环用来判断密码是否吻合
{&&&XMAN;& for(int i=0;n;
cout&如果密码吻合
cout&一旦不相同就将 isok 设置为 false 同时推出循环
cout&lt,再在程序里加上功能选择的代码;system(&文件输入输出流定义 ifstream +流的名字 用于从文件中读入数据
char temp[PASSLEN];/ cout&/return 0;& for(int i=0;pass[i]+PASS&lt葺接壁可撰玖刁擞,注册时扫描一遍文件中的名字;PASS CHECK CORRECT ;/pause&&&& /&PASSLEN;/&&
cin&&#47。;pause&&gt!&
if(input[i];&len。;& /&quot,0。;system(&/1 FOR CHANGE PASS OTHER NUMBER FOR CONTIUNE;& &quot:&i& 文件输入输出流 #define PASSLEN 16#define PASS 3123
&#47.txt&}int main(){
char input[PASSLEN];&从键盘和文件分别读入密码 int len=strlen(input)!=char(pass)) / fin&temp,输入正确可以修改密码;i&/ else pause&判断密码是否吻合
memset( cout& bool isok=&/
changepass()!=0)
我当时急用,是做C语言的课程设计,你给我的是C++的程序,用不了,后来在别的地方弄到了合适的代码,现在已经用不到了。虽然没帮到我,但还是谢谢你
嘿嘿,太客气了,大家一起学习嘛!
其他类似问题
修改密码的相关知识
等待您来回答
您可能关注的推广
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 c语言编程软件 的文章

 

随机推荐