//可以在整型有序数组中查找想要的数字,
//找到了返回下标,找不到返回 - 1.(折半查找)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 10
int main() {
int arr[SIZE] = { 1, 3, 12, 23, 24,25,34,35,45,46};
int left = 0;
int right = SIZE - 1;
int to_find;
printf("输入要查找的数:");
scanf("%d", &to_find);
int mid;
while (left <= right) {
mid = (left + right) / 2;
if (to_find < arr[mid]) {
right = mid - 1;
}
else if (to_find > arr[mid]) {
left = mid + 1;
}
else {
break;
}
}
if (left <= right) {
printf("找到了!\n");
printf("下标为%d.\n", mid);
}
else {
printf("没找到!\n");
}
system("pause");
return 0;
}
//.编写代码模拟三次密码输入的场景。
//最多能输入三次密码,密码正确,提示“登录成功”, 密码错误,
//可以重新输入,最多输入三次。三次均错,则提示退出程序。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
double P_Word = 19990311;
double My_P_word[20] = { 0 };
for (int i = 0; i < 3; i++) {
scanf("%s", &My_P_word);
if (strcmp(My_P_word, "19990311") == 0) {
printf("登陆成功!\n");
break;
}
else {
printf("密码错误!请重新输入:\n");
}
if (i == 3) {
break;
}
}
system("pause");
return 0;
}
//编写一个程序,可以一直接收键盘字符,
//如果是小写字符就输出对应的大写字符,
//如果接收的是大写字符,就输出对应的小写字符,
//如果是数字不输出。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main() {
while (1) {
char Letter = getchar();
if (Letter == '#') {
break;
}
if (Letter >= 'A' && Letter <= 'Z') {
putchar(Letter + 32);
}
else if (Letter >= 'a' && Letter <= 'z') {
putchar(Letter - 32);
}
else {
putchar(' ');
}
}
printf("\n");
system("pause");
return 0;
}