Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

array using dynamic allocation

// array using dynamic allocation


#include <stdio.h>

#include<stdlib.h>


int main() {

    

    int i, n;

    

    int *ptr;

    

    printf("enter the number of elements\n");

    scanf("%d",&n);

    

    ptr = (int*)malloc(n * sizeof(int));

    

    printf("enter the array elements\n");

    

    for ( i = 0 ; i < n ; i++)

    {

        scanf("%d",&ptr[i]);

  }

    printf("printing array elements\n");

     for ( i = 0 ; i < n ; i++)

    {

        printf("%d\n",ptr[i]);      

    }   

    return 0;

}

Post a Comment

0 Comments