bsc

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

pc-ip-10.c (1496B)


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