//是不是这样````````
//假设密码是数字
//程序如下:
#include<stdio.h>
int main(void)
{
const long password = 1234; //存放待对比的数
long inputpsd = 0, i = 1; //inputpsd变量存放用户输入的数, i是输入的次数
do
{
printf("Enter your password:");
scanf("%d", &inputpsd);
while(getchar()!='\n'); //对输入非法字符的处理
if (inputpsd!=password)
{
i++;
printf("Error,try agian.\n");
}
else break;
}while (i<=3);
if (i<4)
printf("OK.\n");
return 0;
}
温馨提示:答案为网友推荐,仅供参考