1. Arrays
The address of the array is the initial address of the first element, the name of the array, which represents the address of the array, and is a constant;
Array Small label: the position of the element in the array is represented by the subscript, and the following table is zero-based, so the index of the array of the maximum value can only be reduced to the length of the number one, using the process of attention to the following table do not cross the border;
Array initialization
(1) Assigning values directly to all elements
(2) Assign a value to some elements, the unassigned element defaults to zero;
(3) Directly omit the length, the number of elements in curly braces is the length of the array;
The important usage in the array "bubble sort": Assuming that the array has n elements, then the outermost loop (the control loop compares how many times) variable (i) need i<n-1, the inner loop (how many times each trip to compare), the loop variable (j) needs j<n-i-i;
For example, the arrangement is the size of the number
#include <stdio.h>
int main ()
{
int a[10]={8,44,43,56,87,90,65,78,69,70};
int i,j,t;
for (i=0;i<10;i++)
{
for (j=0;j<10-i;j++)
{
if (a[j]>a[j+1])
{
T=A[J];
A[J]=A[J+1];
a[j+1]=t;
}
}
}
printf ("%d", a[j]);
return 0;
}
The actual use of an array of life: Enter a month and a day to judge him as the first day of the year
#include <stdio.h>
int main ()
{
int h[12]={31,29,31,30,31,30,31,30,31,30,31,30};
int p[12]={31,28,31,30,31,30,31,30,31,30,31,30};
int z,b,c,k=0,i,s;
printf ("Please enter the date you want to find");
scanf ("%d,%d,%d", &z,&b,&c);
if ((z%4==0&&z?100!=0) | | | (z%400==0)) The judgement of the year, if it is leap years, a for loop
{
for (i=0;i<b-1;i++) {
K + = H[i];
}
S=k+c;
}
if ((z%4!=0) | | | (z%4==0&&&z%100==0&&z%400!=0) {
for (i=0;i<b-1;i++) {
k= K+p[i];
}
S=k+c;
}
printf ("This is%d days of the year \ n", s);
return 0;
}
Basic outline of C language----array