bsc

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

IP-10.c (1475B)


      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 function that reverses the elements of an array in place, using only a single
      9 pointer argument, and return void. */
     10 
     11 #include <stdio.h>
     12 #include <stdlib.h>
     13 
     14 void inputArray(int[], int);
     15 void printArray(int[], int);
     16 void reverse(int *);
     17 
     18 int main()
     19 {
     20     int n, i, *arr = NULL;
     21     printf("Enter the number of element: ");
     22     scanf("%d", &n);
     23     arr = (int *)malloc(n * sizeof(int));
     24     if (arr == NULL)
     25     {
     26         printf("\nMemory allocation failed.");
     27         return 1;
     28     }
     29     inputArray(arr, n);
     30     printf("\nGiven Array: ");
     31     printArray(arr, n);
     32     for (i = 0; i < n; i++)
     33     {
     34         reverse(&arr[i]);
     35     }
     36     printf("\nUpdated Array: ");
     37     printArray(arr, n);
     38     free(arr);
     39     return 0;
     40 }
     41 
     42 void inputArray(int arr[], int n)
     43 {
     44     int i;
     45     for (i = 0; i < n; i++)
     46     {
     47         printf("Enter element %d: ", i + 1);
     48         scanf("%d", &arr[i]);
     49     }
     50 }
     51 
     52 void printArray(int arr[], int n)
     53 {
     54     int i;
     55     printf("[");
     56     for (i = 0; i < n; i++)
     57     {
     58         printf("%d", arr[i]);
     59         if (i < n - 1)
     60         {
     61             printf(", ");
     62         }
     63     }
     64     printf("]");
     65 }
     66 
     67 void reverse(int *n)
     68 {
     69     int temp = *n;
     70     int rev = 0;
     71     while (temp > 0)
     72     {
     73         rev = (rev * 10) + (temp % 10);
     74         temp /= 10;
     75     }
     76     *n = rev;
     77 }
© 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