当前位置:网站首页>C primre plus Chapter 10 question 6 inverted array
C primre plus Chapter 10 question 6 inverted array
2022-07-03 04:29:00 【multydoffer】
Write a function , hold int The data in the type array is arranged in reverse order , And test the function in a simple program .
If you don't open an additional array , The code is as follows :( But there may be a better algorithm ?)
#include <stdio.h>
#define SIZE 12
void reverse(int * a, int n);
int main(void)
{
int a[SIZE] = {3, 4431, 43, 23, 35, 35, 1, 34, 234, 35, 3, 1 };
int i = 0;
reverse(a, SIZE);
for(i = 0; i < SIZE; i++)
{
printf("a[%d] ", i);
}
printf("\n");
for(i = 0; i < SIZE; i++)
{
printf("%-6d", a[i]);
}
return 0;
}
void reverse(int * a, int n)
{
int i = 0;
int j = n - 1;
int temp;
for(; i < j; i++, j--)
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
return;
}
边栏推荐
- How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
- 540. Single element in ordered array
- Kingbasees plug-in KDB of Jincang database_ exists_ expand
- [set theory] binary relationship (special relationship type | empty relationship | identity relationship | global relationship | divisive relationship | size relationship)
- redis 持久化原理
- How to choose cross-border e-commerce multi merchant system
- [nlp] - brief introduction to the latest work of spark neural network
- [dynamic programming] subsequence problem
- What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
- 2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis
猜你喜欢
redis 持久化原理
JS realizes lazy loading of pictures
Feature_selection
Prefix and (continuously updated)
使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
C language series - Section 3 - functions
Design and implementation of JSP logistics center storage information management system
How to choose cross-border e-commerce multi merchant system
跨境电商多商户系统怎么选
Youdao cloud notes
随机推荐
What functions need to be set after the mall system is built
[Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
Basic syntax of class
Golang -- realize file transfer
2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination
Ffmpeg mix
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
Kingbasees plug-in KDB of Jincang database_ exists_ expand
Ffmpeg tanscoding transcoding
Library management system based on SSM
[dynamic programming] subsequence problem
Priv app permission exception
2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis
vulnhub HA: Natraj
[fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
JS realizes the animation effect of text and pictures in the visual area
Matplotlib -- save graph
When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully
[free completion] development of course guidance platform (source code +lunwen)
Php+mysql registration landing page development complete code