C/C++ SIGSEGV error problem HELP

Heading ## - List item

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
int a,b[34],d,c=0;
char *arr;
scanf("%d",&a);
while(a–){
gets(arr);
d= strlen(arr);
if(d==0||d==1)
scanf("%d",b[c++]=0);
else if(d==2)
scanf("%d",b[c++]=1);
else
scanf("%d",b[c++]=(1+ pow((d-2),2)));
}
a=0;
while(c–)
{
printf("\n%d",b[++a]);
}
return 0;
}

This is my code. i don’t understand why it always gives SIGSEGV error. i have runned it several times. HELP.
Problem code: TNMALG04

the approach you are using is not the right way of doing problem TNMALG04.you should use other trick.and your logic is also not right here you are using scanf for assigning value in c???..scanf is used for taking input only and it returns the count of input it has taken.correct your code.

3 Likes

you can use following approach to the solution dp[0]=1; and

   function preprocess()
    for i =1 to n
    do
    dp[i]=dp[i-1]*(2*i)*(2*i-1)/(i*(i+1))

now you can return the output returning the value from array.

3 Likes

i see several issues here… the variable ‘arr’ is just a pointer. there is no memory associated with it. running this program with a debugger would have shown this. i am pretty sure that scanf doesn’t work thag way.

there are some things that cannot be optimized just like that. scanf is one of those things!