Array sorting and two-dimensional arrays

Source: Internet
Author: User

////main.c//array Sorting and two-dimensional arrays////Created by zhangxueming on 15/6/1.//Copyright (c) 2015 zhangxueming. All rights reserved.//#include<stdio.h>//Bubble sort (small to large)//9 7 8 5 3--3 5 7 8 9//First time sort//7 9 8) 5 3//7 8 9) 5 3//7 8 5) 9 3//7 8 5) 3 9//Second Sort//7 8 5) 3 9//7 5 8) 3 9//7 5 3) 8 9//Third Sort//5 7 3) 8 9//5 3 7) 8 9//fourth time sort//3 5 7) 8 9#defineLEN 5//int main (int argc, const char * argv[]) {//int a[len]={};//    //Input Array//for (int i=0; i<len; i++) {//scanf ("%d", &a[i]);//    }//    //Bubble Sort//for (int i=0; i<len-1; i++) {//for (int j=0; j<len-i-1; J + +) {//if (a[j]>a[j+1]) {//int temp= a[j];//a[j]=a[j+1];//a[j+1]=temp;//            }//        }//    }//    //Traverse Output//for (int i=0; i<len; i++) {//printf ("%d", A[i]);//    }//printf ("\ n");//return 0;//}//Select Sort//9 7 8 5 3 k=4 a[k] a[i]//First time sort//3 7 8) 5 9//Second Sort//3 5 8) 7 9//Third Sort//3 5 7) 8 9//fourth time sort//3 5 7) 8 9//int main (int argc, const char *argv[])//{//int a[len]={};//    //Input Array//for (int i=0; i<len; i++) {//scanf ("%d", &a[i]);//    }//    //Select Sort//for (int i=0; i<len-1; i++) {//int k=i;//record the lowest value subscript//for (int j=i+1; j<len; J + +) {//if (A[k]>a[j]) {//k=j;//            }//        }//if (k!=i) {//int temp = a[k];//A[k]=a[i];//a[i]=temp;//        }//    }//    //Output Array//for (int i=0; i<len; i++) {//printf ("%d", A[i]);//    }//printf ("\ n");//return 0;//}//Insert Sort//9 7 8 5 3 int temp = 7;//First time sort//9 9 8) 5 3//7 9 8) 5 3//Second Sort temp = 8;//7 9 9) 5 3//7 8 9) 5 3//Third Sort temp = 5;//7 8 9) 9 3//7 8 8) 9 3//7 7 8) 9 3//5 7 8) 9 3//fourth time Sort temp = 3;//5 7 8) 9 9//5 7 8) 8 9//5 7 7) 8 9//5 5 7) 8 9//3 5 7) 8 9//int main (int argc,const char *argv[])//{//int a[len]={};//for (int i=0; i<len; i++) {//scanf ("%d", &a[i]);//    }//    //Insert Sort//for (int i=0; i<len-1; i++) {//int temp = a[i+1];//int j=i;//        //Control Shift//While (a[j]>temp && j>=0) {//A[j+1]=a[j];//j--;//        }//        //inserting elements//a[j+1]=temp;//    }//for (int i=0; i<len; i++) {//printf ("%d", A[i]);//    }//printf ("\ n");//    //return 0;//}//int a[5]//int a[3][4][5]//Two-dimensional arrays: one-dimensional arrays consisting of one-dimensional arrays as elements//int a[3][4];//a[0] a[1] a[2] is an array of 4 elements of type int//initialization of two-dimensional arrays//int main (int argc,const char *argv[])//{//int a[3][2]={1,[2][0]=3,4};//for (int i=0; i<3; i++) {//for (int j=0; j<2; J + +) {//printf ("%d", a[i][j]);//        }//printf ("\ n");//    }//return 0;//}//int main (int argc, const char *argv[])//{//int a[3][4]={{1,2,3,4},//{5,6,7,8},//{9,10,11,12}};//    //for (int i=0; i<3; i++) {//for (int j=0; j<4; J + +) {//printf ("%4d", A[i][j]);//        }//printf ("\ n");//    }//return 0;//}//1//1 1//1 2 1//1 3 3 1//1 4 6) 4 1//1 5 5 1intMainintargcConst Char*argv[]) {    inta[Ten][Ten]={};  for(intI=0; i<Ten; i++) {         for(intj=0; j<=i; J + +) {            if(j==0|| j==i) {a[i][j]=1; }            Else{A[i][j]=a[i-1][j]+a[i-1][j-1]; }        }    }     for(intI=0; i<Ten; i++) {         for(intj=0; j<=i; J + +) {printf ("%4d", A[i][j]); } printf ("\ n"); }    return 0;}

Array sorting and two-dimensional arrays

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.