12-08 about bubbling sort and array

Source: Internet
Author: User

I. Integral type array: int numsarray[]

Floating-point array: float scorearray[]

Array of strings: numsarray[]

When defining an array, you must be able to determine the number of elements in the array.

Two. Define an array with 5 elements, the default value of each element = 0;

1?? int numsarray[5];(5*4=20 memory space)

There are 5 elements in the array, each of which is an integral type.

2?? int numsarray[]={1,2,3,4};(4*4=16 memory space)

Defines an array with four elements, followed by 1,2,3,4

3?? int numsarray[5]={1,2};(5*4=20 memory space)

Defines an array that has 5 elements, the first is 1, the second bit 2, and the default is 0.

Three. Accessing array functions

The index value starts at 0, for example:

The int numsarray[0]//corresponds to the index value starting with 0, the first element within the array.

Array: Used to store multiple data of the same type

Four. Set the seed of random number in C language

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main () {

Srand ((unsigned int) time (NULL));

for (int i = 0;i<5;i++) {

printf ("%d", rand ()%9+1);

}

printf ("\ n");

return 0;

}

Five. Bubble sort

int temp;

for (int i = 0;i <4;i + +) {

for (Int J =4-1-1;j >=i; J--) {

if (Array[j] > array[j+1]) {

temp = array[j+1];

ARRAY[J] = array[j+1];

ARRAY[J+1] = temp;

}

}

}

12-08 about bubbling sort and array

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.