{
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int arr[3][5] = { {1,2,3},{2,5,60},{1} };
for (int a = 0; a < 3; a++)
{for(int b=0;b<5;b++)
printf("%d\n", arr[a][b]);//二维数组
}
return 0;
}
```c
```c
在这里插入代码片
数组arr1与arr2内容的交换
{
{
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<windows.h>
char arr1[] = "welcome to bit!!!!!";
char arr2[] = "*******************";
size_t left = 0;
size_t right = strlen(arr1)-1;
while (left<=right)
{
arr2[left] = arr1[left];
arr2[right] = arr1[right];
left++;
right--;
printf("%s\n", arr2);
Sleep(1000);//休眠,单位是毫秒
system("cls");//引用#include<windows.h>的库函数
}
printf("%s\n", arr1);
return 0;}
}
二分查找在有序的数组中,查找指定的数值
//升序
//[1 2 3 4 5 6 7 8 9 10]
int main()
{
int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
int k = 7;
int i = 0;
int sz = sizeof(arr) / sizeof(arr[0]);
for (i = 0; i < sz; i++)
{
if (arr[i] == k)
{
printf("找到了,下标是:%d\n", i);
break;
}
}
if (i == sz)
printf("找不到\n");
return 0;
}
int main()
{
int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
int k = 0;
scanf("%d", &k);
int sz = sizeof(arr) / sizeof(arr[0]);
int left = 0;
int right = sz - 1;
while (left<=right)
{
int mid = (left + right) / 2;//被查找范围的中原元素的下标
if (arr[mid] < k)
{
left = mid + 1; }
else if (arr[mid] > k)
{
right = mid - 1;
}
else
{
printf("找到了,下标是:%d\n", mid);
break;
}
}
if (left > right)
printf("找不到了\n");
return 0;
}
int main()
{
int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
int k = 0;
scanf("%d", &k);
int sz = sizeof(arr) / sizeof(arr[0]);
int left = 0;
int right = sz - 1;
int flag = 0;//假设找不到
while (left <= right)
{
int mid = (left + right) / 2;//被查找范围的中原元素的下标
if (arr[mid] < k)
{
left = mid + 1;
}
else if (arr[mid] > k)
{
right = mid - 1;
}
else
{
printf("找到了,下标是:%d\n", mid);
flag = 1;//找到了
break;
}
}
if (flag == 0)
printf("找不到了\n");
return 0;
}