当前位置:网站首页>Using C language to realize the exchange between the contents of two arrays (provided that the array is the same size)
Using C language to realize the exchange between the contents of two arrays (provided that the array is the same size)
2022-07-01 00:58:00 【Sky • Shang】
for example : take int arr1[] = { 1, 3, 5, 7, 9 };
int arr2[] = { 2, 4, 6, 8, 0 };
The contents of these two arrays are exchanged
#include <stdio.h>
int main()
{
int arr1[] = { 1, 3, 5, 7, 9 };
int arr2[] = { 2, 4, 6, 8, 0 };
int change[5] = { 0 }; // A temporary array is created here
int i = 0;
for (i = 0; i < 5; i++)
{
change[i] = arr1[i];
arr1[i] = arr2[i];
arr2[i] = change[i];
}
int m = 0;
for (m = 0; m < 5; m++) // All printing of the array must be done with for loop
{
printf("%d", arr1[m]);
}
printf("\n");
int n = 0;
for (n = 0; n < 5; n++)
{
printf("%d", arr2[n]);
}
return 0;
}The key is :
You can create a temporary array , You can also create a temporary variable
It's easy to get wrong :
Print all array elements
common Wrong way :

So only Random values are printed
therefore ,
You can only choose for Loop to print all elements of the array
边栏推荐
- [original] PLSQL index sorting optimization
- 2022 is half way through. It's hard to make money
- 问题解决:如何管理线程私有(thread_local)的指针变量
- left join左连接匹配数据为NULL时显示指定值
- 2022-2028 global rampant travel industry research and trend analysis report
- 2022-2028 global herbal diet tea industry research and trend analysis report
- Oracle data integrity
- P4学习——Basic Tunneling
- Oracle-表的创建与管理
- 对libco的一点看法
猜你喜欢

2022-2028 global plant peptone industry research and trend analysis report

Can JDBC based on openjdk connect to MySQL?
![[untitled]](/img/96/7f26614bbdcce71006e38ee34ab216.jpg)
[untitled]

From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years

20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking

2022-2028 global single travel industry research and trend analysis report

20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br

Cmu15445 (fall 2019) project 1 - buffer pool details

SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding

Wechat official account development (1) introduction to wechat official account
随机推荐
Oracle temporary table explanation
Integer to hexadecimal string PTA
IBL预计算的疑问终于解开了
Longest valid bracket
Yboj mesh sequence [Lagrange interpolation]
leetcode 474. Ones and Zeroes 一和零(中等)
Stack frame
Basic data structure of redis
Ranger plug-in development (Part 2)
CentOS install MySQL
对libco的一点看法
2022-2028 global ethylene oxide scrubber industry research and trend analysis report
2022-2028 global herbal diet tea industry research and trend analysis report
Pytorch installs and uses GPU acceleration
20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
2022-2028 global 3D printing ASA consumables industry research and trend analysis report
2022-2028 global PTFE lined valve industry research and trend analysis report
Pytorch auto derivation
Rust controls Dajiang programmable UAV Tello
解决 error MSB8031: Building an MFC project for a non-Unicode character set is deprecated.