#define UC (1U<<1) // upper case
#define LC (1U<<2) // lower case
#define NUM (1U<<3) // 0-9
#define ALL (UC|LC|NUM)
int check(const char pass1[], const char pass2[])
{
const char *p = &pass1[0]
unsigned int flag = 0
if (strlen(pass1) <6 || strlen(pass1) >8)
{
printf("password length is 6 to 8.\n")
return 1
}
if (strcmp(pass1, pass2))
{
printf("the tow passwords are diffrence.\n")
return 2
}
while (*p)
{
if (*p >= 'a' &&*p <= 'z') flag |= LC
else if (*p >= 'A' &&*p <= 'Z') flag |= UC
else if (*p >= '0' &&*p <= '9') flag |= NUM
else
{
printf("in valid charactor: %c.\n", *p)
return 3
}
++p
}
if (flag == ALL) return 0
if ((flag &UC) == 0)
{
printf("lack of uppercase.\n")
}
if ((flag &LC) == 0)
{
printf("lack of lowercase.\n")
}
if ((flag &NUM) == 0)
{
printf("lack of number.\n")
}
return -1
}
int main(int argc, char *argv[])
{
char pass1[100]
char pass2[100]
do {
printf("input password:")
scanf("%s", pass1)
printf("repeat password:")
scanf("%s", pass2)
} while (check(pass1, pass2) != 0)
return 0
}
#include <stdio.h>#include <string.h>
#include <stdlib.h>
#define pi 3.1415926
float area(float s)
void main()
{
char srmima[16],mima[16]="sunshibin1020"
int i=0,j
float r,s
while(1)
{
for(j=0j<30j++)
printf("-")
printf("\n")
gets(srmima)
for(j=0j<30j++)
printf("-")
printf("\n")
if(strcmp(srmima,mima)==0)
{
printf("恭喜你,密码正确!\n")
break
}
i++
if(i>2)
{
printf("很遗憾,密码输入错误!\n")
exit(0)
}
}
area(r)
printf("圆面积为:%f",s)
getchar()
}
float area(float r)
{
float s
while(1)
{
printf("\n请输入半径: r:")
scanf("%f",&r)
if (r<0)
break
s=pi*r*r
printf("s=%.2f\n",s)
}
exit(0)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)