sigsegv error again and again for factorial problem in easy. I AM new please help!

#include<stdio.h>
int main()
{
int n;
int totline,ptr,i;
ptr=(int
)calloc(n,sizeof(int));
scanf("%d", &totline);
for( i=0; i<totline ;i++)
{ scanf("%d", &n);
( ptr+i)=0;
while(1)
{
n=n/5;
(
(ptr+i))+=n;
if(n==0)
break;
}
}
for(i=0;i<totline;i++)
printf("%d\n", *(ptr+i));
free(ptr);
return 0;
}

1 Like

Please refer this: SIGSEV errors answers here

1 Like

To help you a little more…

…link provided by @namankumar is correct.

This part is related to you:

Make sure you aren’t declaring too much memory. 64 MB is guaranteed, but having an array of size [10000][10000] will never work.

N is up to 109, so how big memory you need for calloc(n,sizeof(int)); ? Let’s assume, that size of int is 4 bytes :wink:

then how should i declare memory based on the input of n,pls help?

but calloc() will initialize the memory booking based on the input.so if i say n is small(depends on input) then it allocate only n*4 bytes which is good.

But N can be as big as I wrote, so you cannot assume it is small. You have to find another approach…