1.编写代码,演示多个字符从两端移动,向中间汇聚
#define _CRT_SECURE_NO_WARNINGS #include#include #include int main() { char arr1[] = "welcome to Lizixiaohanhan"; char arr2[] = "#########################"; int left = 0; int right = strlen(arr1) - 1; while (left <= right) { arr2[left] = arr1[left]; arr2[right] = arr1[right]; printf("%sn", arr2); Sleep(1000); left++; right--; } return 0; }
2.编写代码,模拟用户登录情形,并且只能登录三次。
#define _CRT_SECURE_NO_WARNINGS #include#include int main() { int i = 0; char password[20] = { 0 }; for (i = 0;i < 3;i++) { printf("请输入密码:>"); scanf("%s", password); if (strcmp(password, "123456") == 0) { printf("登陆成功n"); break; } else { printf("密码错误,请重新输入!n"); } } if (i == 3) printf("三次密码均错误,推出n"); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)