C Program Of Calloc(C library function)

C Program Of Calloc(C library function)

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

main()
{

int i,n,*ptr,*p,sum=0;

printf("Enter array size:\n");
scanf("%d",&n);

ptr=(int*)calloc(n,sizeof(int));
p=ptr;


if(ptr==NULL)
{

printf("Error in creating Memory\n");
exit(0);

}

printf("Enter array elements:\n");

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

scanf("%d",ptr);

sum=sum+*ptr;
ptr++;

}

printf("\n");
printf("Array element is:\n");

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

{
printf("%d\n",*p);
p++;

}

printf("Sum is :%d\n",sum);

}

Related Posts