A C language program

3个回答

  • #include

    #include

    #include

    #include

    #include

    void fillRandom(int * x , int n);

    void printArray(int * x, int n, int k);

    void doSort(int ** x, int n);

    void copyArray (int * a,int * b,int n);

    int main ()

    {

    int a[10];int i;int b[10];int c[10];int rn=0;

    srand(time(NULL));

    fillRandom(a,10);

    printf("This is Array a:n");

    printArray(a,10,10);

    printf("Array not sortedn");

    copyArray(a,b,10);

    printf("nThis is Array b(copy from Array a):n");

    printArray(b,10,10);

    doSort(b,10);

    printf("nArray b is sorted now:n");

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

    { printf("%d ", b[i]);

    }

    fillRandom(c,10);

    printf("nnThis is Array c:n");

    printArray(c,10,10);

    doSort(c,10);

    printf("nThe Largest in Array c is: %dn",c[0]);

    printf("The smallest in Array c is: %dn",c[9]);

    printf("The middle values of Array c are %d and %dn",c[5],c[4]);

    doSort(a,10);

    printf("n%d is the largest in Array an",a[0]);

    printf("%d is the largest in Array cn",c[0]);

    printf("nenter a number to see if it is in Array a:");scanf("%d",&rn);

    if ((rn==a[0])||(rn==a[1])||(rn==a[2])||(rn==a[3])||(rn==a[4])||(rn==a[5])||(rn==a[6])||(rn==a[7])||(rn==a[8])||(rn==a[9]))

    printf("Yes!n");

    else

    printf("Not foundn");

    getch ();

    return 0;

    }

    void fillRandom(int * x , int n)

    {

    int i=0;

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

    x[i]= (rand()%(99-10+1) + 10);

    }

    void printArray(int * x, int n, int k)

    { int i;

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

    { printf("%d ",x[i]);

    if((i+1)%k==0)

    printf("n");

    }

    }

    void copyArray (int * a,int * b, int n)

    { int i;

    for (i=0; i