Increment Every Element of the Array by One & Print Incremented Array

Given an array, increment all the elements of the array by 1 and print the incremented array.


For example:

If the array is
1 2 3 4 5

then the resultant array is
2 3 4 5 6

Implementation:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
 int *a,i,n;
 
 /* Get the number of elements of the array */
 scanf("%d",&n);
 
 /* allocate the memory for n integers & store the starting address of the block in a */
 a=(int*)malloc(sizeof(int)*n);
 
 /* Get the elements of the array from the user */
 for(i=0;i<n;i++)
  scanf("%d",(a+i));
 
 /* Increment every element in the array by 1 */
 for(i=0;i<n;i++)
  *(a+i)+=1;
  
 /* Print the incremented array */
 for(i=0;i<n;i++)
  printf("%d ",*(a+i));
  
 return 0;
}