在单个数组中对两半执行操作的 C 程序
问题
编写一个程序来接受一个由N个元素组成的一维数组并分成两半。稍后,将前半部分按升序排序,将后半部分按降序排序。
解决方案
下面解释了在C编程语言中对单个数组中的两半执行两个操作的解决方案-
用于按升序对前半部分进行排序的逻辑如下-
for (i=0; i number[j]){
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}用于按降序对后半部分进行排序的逻辑如下-
for (i=b; i用于将数组分成两半并相应打印的逻辑如下-
上半场升序
for (i=0; i下半场降序
for(i=b;i示例
以下是对单个数组中的两半执行两个操作的C程序-
#includevoid main(){ int i,j,a,n,b,number[30]; printf ("Enter the value of N\n"); scanf ("%d", &n); b = n/2; printf ("Enter the numbers \n"); for (i=0; i number[j]){ a = number[i]; number[i] = number[j]; number[j] = a; } } } for (i=b; i 输出结果 执行上述程序时,会产生以下结果-
Enter the value of N 10 Enter the numbers 20 34 23 11 45 56 78 98 76 54 The 1st half numbers arranged in asc 11 20 23 34 45 The 2nd half Numbers order arranged in desc.order 98 78 76 56 54
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短