bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

IP-20.c (1332B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 03 Jan 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Write a C program that defines an array of integers, and includes a user-defined function
      9 named reverseArray with the signature void reverseArray(int arr[], int size);. The function
     10 should reverse the elements of the array. */
     11 
     12 #include <stdio.h>
     13 
     14 void inputArray(int[], int);
     15 void reverseArray(int[], int);
     16 
     17 int main()
     18 {
     19     int size;
     20     printf("How many element do you want to add: ");
     21     scanf("%d", &size);
     22     int arr[size];
     23     inputArray(arr, size);
     24     reverseArray(arr, size);
     25     return 0;
     26 }
     27 
     28 void inputArray(int arr[], int size)
     29 {
     30     int i;
     31     for (i = 0; i < size; i++)
     32     {
     33         printf("Enter element %d: ", i + 1);
     34         scanf("%d", &arr[i]);
     35     }
     36 }
     37 
     38 void reverseArray(int arr[], int size)
     39 {
     40     int i, j, temp;
     41     printf("\nBefore Reverse: \n");
     42     for (i = 0; i < size; i++)
     43     {
     44         printf("Position: %d, Value: %d\n", i, arr[i]);
     45     }
     46     for (i = 0, j = size - 1; i < j; i++, j--)
     47     {
     48         temp = arr[i];
     49         arr[i] = arr[j];
     50         arr[j] = temp;
     51     }
     52     printf("\nAfter Reverse: \n");
     53     for (i = 0; i < size; i++)
     54     {
     55         printf("Position: %d, Value: %d\n", i, arr[i]);
     56     }
     57 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror