Thursday, June 16, 2016

C Language Code: តំរៀបArrayចំនួនគត់ពីធំទៅតូច

C Language Code

#include<stdio.h>
int main()
{
    int i, temp, arrayLength;
    int array[100];
    printf("C Program to Reverse Array Elements \n");
    printf("Enter Array Length : ");
    scanf("%d", &arrayLength);

    if (arrayLength <= 100)
    {
        //input array elements
        printf("Enter Array Elements \n");
        for (i = 0; i < arrayLength; i++)
        {
            printf("Array[%d] = ", i);
            scanf("%d", &array[i]);
        }
        //Swap the array elements
        for (i = 0; i < (arrayLength / 2); i++)
        {
            temp = array[i];
            array[i] = array[(arrayLength - 1) - i];
            array[(arrayLength - 1) - i] = temp;
        }
        printf("Array After Reversing \n");
        //Display array elements
        for (i = 0; i < arrayLength; i++)
        {
            printf("Array[%d] = %d \n", i, array[i]);
        }
    }
    else
    {
        printf("Array Length is too large \n");
    }

    printf("Press enter to continue... \n");
    getch();
    return 0;
}


Reverse Array in C Output Screenshot