write a program to allocate the memory dynamically using malloc.
#include<stdio.h>  #include<conio.h>  #include<stdlib.h>  int main()  {  int i,n;  int *ptr;  printf("enter the no. of elements\n");  scanf("%d",&n);  ptr=(int*)malloc(n*sizeof(int));  printf("memory allocated\n");  for(i=0;i<n;i++)  {  ptr[i]=i+1;  }  printf("elements in the array are\n");  for(i=0;i<n;i++)  {  printf("%d\n",ptr[i]);  }  return 0;  }                                     
  
  
  
Comments
Post a Comment