c语言实现,每次输入8个数,存入代码的数组中。这些数组不能重复,重复会弹出提示。存到5个数组,开始输出。
时间: 2024-05-24 18:12:30 浏览: 14
#include <stdio.h>
#include <stdbool.h>
#define SIZE 8
#define MAX_ARR 5
bool is_in_array(int arr[], int size, int num);
void print_array(int arr[], int size);
int main() {
int arr[MAX_ARR][SIZE] = {0};
int count = 0; // 记录已经存储的数组个数
while (count < MAX_ARR) {
int input[SIZE] = {0};
printf("请输入8个数:");
for (int i = 0; i < SIZE; i++) {
scanf("%d", &input[i]);
if (is_in_array(arr[count], SIZE, input[i])) {
printf("输入的数不能重复!\n");
i--; // 重新输入重复的数
}
}
// 将输入的数组存入二维数组中
for (int i = 0; i < SIZE; i++) {
arr[count][i] = input[i];
}
count++;
}
// 输出所有的数组
for (int i = 0; i < MAX_ARR; i++) {
printf("第%d个数组:", i + 1);
print_array(arr[i], SIZE);
printf("\n");
}
return 0;
}
// 判断一个数是否在数组中出现过
bool is_in_array(int arr[], int size, int num) {
for (int i = 0; i < size; i++) {
if (arr[i] == num) {
return true;
}
}
return false;
}
// 输出一个数组的所有元素
void print_array(int arr[], int size) {
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)