bsc

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

pc-ip-20.c (1545B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 05 Jan 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /*
      9  * Question 20:
     10  * Write a C program that defines an array of integers, and includes a user-defined function named reverseArray with the signature void reverseArray(int arr[], int size);.
     11  */
     12 
     13 #include<stdio.h>
     14 #include<stdlib.h>
     15 
     16 void inputArray(int [], int);
     17 void reverseArray(int [], int);
     18 void printArray(int [], int);
     19 
     20 int main() {
     21     int n, *arr = NULL;
     22     printf("How many element do you want enter: ");
     23     scanf("%d", &n);
     24     arr = (int *)malloc(n * sizeof(int));
     25     if(arr == NULL) {
     26         printf("\nMemory allocation failed.");
     27         return 1;
     28     }
     29     inputArray(arr, n);
     30     printf("\nBefore Reverse: ");
     31     printArray(arr, n);
     32     reverseArray(arr, n);
     33     printf("\nAfter reverse: ");
     34     printArray(arr, n);
     35     free(arr);
     36     return 0;
     37 }
     38 
     39 void inputArray(int arr[], int n) {
     40     int i;
     41     for(i = 0; i < n; i++) {
     42         printf("Enter element %d: ", i + 1);
     43         scanf("%d", &arr[i]);
     44     }
     45 }
     46 
     47 void printArray(int arr[], int n) {
     48     int i;
     49     printf("[");
     50     for(i = 0; i < n; i++) {
     51         printf("%d", arr[i]);
     52         if(i < n - 1) {
     53             printf(", ");
     54         }
     55     }
     56     printf("]");
     57 }
     58 
     59 void reverseArray(int arr[], int size) {
     60     int i = 0;
     61     int j = size - 1;
     62     int temp;
     63     while(i < j) {
     64         temp = arr[i];
     65         arr[i] = arr[j];
     66         arr[j] = temp;
     67         i++;
     68         j--;
     69     }
     70 }
© 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