Create an array, using functions to initialize, empty, and reverse each of them. You design the parameters of the function, return the value

Source: Internet
Author: User

Creates an array,

The implementation function init () initializes the array,

Implement empty () to empty the array,

Implements the reverse () function to complete the inverse of the array element.

Requirements: You design the parameters of the function, return the value. */


#include <stdio.h>

#include <cstdlib>


void Init (int* arr, int length)//does not open space for arr can be uninitialized.

{

int i = 0;

for (i = 0; i<length; i++)

{

Arr[i] = i;//scanf_s ("%d", &arr[i]);


}

}

void Empty (int* arr, int length)

{

int i;

for (i = 0; i<length; i++)

{

Arr[i] = 0;

}

}

void reverse (int* arr, int length)//Exchange address

{

int tmp;

int i;


for (i = 0; i<length/2; i++)

{

TMP = arr[length-i-1];

Arr[length-i-1] = arr[i];

Arr[i] = tmp;

}

}


void printf (int *arr, int length)

{

int i = 0;

for (i = 0; i<length; i++)

{

printf ("%d", arr[i]);

}

printf ("\ n");

}

int main ()

{

int arr[10];

int length = sizeof (arr)/sizeof (arr[10]);

Init (arr, length);

printf (arr, length);

Reverse (arr, length);//cannot be arr[10], which refers to the element labeled 10

printf (arr, length);

Empty (arr, length);

printf (arr, length);


System ("pause");

return 0;

}


Create an array, using functions to initialize, empty, and reverse each of them. You design the parameters of the function, return the value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.