This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12933|Reply: 0

[C] Use the array name as the argument of the function The reverse order of the array

[Copy link]
Posted on 12/10/2015 5:17:11 PM | | |
//数组a中n个整数按相反的顺序存放
Use a function INV to implement it, the actual parameter uses the array name a, and the shape parameter can also use the array name or pointer variable

#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{void inv(int x[],int n); inv function
int i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf("the original array:\n");
for(i=0; i<10; i++)
printf("%d,",a[i]);
printf("\n");
inv(a,10);
printf("the array has been inverted:\n");
for(i=0; i<10; i++)
printf("%d,",a[i]);
printf("\n");
return 0;
}
void inv(int x[],int n)
{int temp,i,j,m=(n-1)/2;
for(i=0; i<=m; i++)
    {j=n-1-i;
     temp=x[i]; x[i]=x[j]; x[j]=temp;
    }
return;
}






Previous:Pointer variables as parameters of the function Compare size
Next:RSA generates public and private keys, as well as encryption and decryption
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com