
数组是一组以单一名称存储的相关数据项。
例如 int Student[30]; //student是一个数组名,包含单个变量名的30个数据项集合
数组的操作
搜索 - 用于查找特定元素是否存在
排序 - 它有助于排列数组中的元素按升序或降序排列。
遍历 - 它按顺序处理数组中的每个元素。
-
插入 - 它有助于在数组中插入元素。
删除 - 它有助于删除数组中的元素。数组中的元素。
在数组中查找偶数的逻辑如下 -
for(i = 0; i <p><strong>在数组中查找奇数</strong>的逻辑如下 -</p><pre class="brush:php;toolbar:false;">for(i = 0; i <p>要显示<strong>偶数</strong>,请调用下面提到的显示函数 -</p><pre class="brush:php;toolbar:false;">printf("no: of elements comes under even are = %d <p>", Ecount);
printf("The elements that are present in an even array is: ");
void display(int a[], int size){
int i;
for(i = 0; i </p><p>");
}</p>
要显示奇数,请按照以下方式调用显示函数 −
printf("no: of elements comes under odd are = %d <p>", Ocount);
printf("The elements that are present in an odd array is : ");
void display(int a[], int size){
int i;
for(i = 0; i </p><p>");
}</p>
程序
以下是使用 for 循环分隔数组中偶数和奇数的 C 程序 -
现场演示
#include<stdio.h>
void display(int a[], int size);
int main(){
int size, i, a[10], even[20], odd[20];
int Ecount = 0, Ocount = 0;
printf("enter size of array :<p>");
scanf("%d", &size);
printf("enter array elements:</p>
<p>");
for(i = 0; i </p>
<p>", Ecount);
printf("The elements that are present in an even array is: ");
display(even, Ecount);
printf("no: of elements comes under odd are = %d </p>
<p>", Ocount);
printf("The elements that are present in an odd array is : ");
display(odd, Ocount);
return 0;
}
void display(int a[], int size){
int i;
for(i = 0; i </p>
<p>");
}</p></stdio.h>
输出
当执行上述程序时,会产生以下结果 -
enter size of array: 5 enter array elements: 23 45 67 12 34 no: of elements comes under even are = 2 The elements that are present in an even array is: 12 34 no: of elements comes under odd are = 3 The elements that are present in an odd array is : 23 45 67
13万字C语言保姆级教程(深入):立即使用
在学习笔记中,你将探索c语言的核心概念和高级技巧!











