|
|
back to boardRuntime error(access violation) #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { long int n,k,val,fact=1,coeff=0;
char ch[24],*num,*excl;
gets(ch);
num=strtok(ch," "); n=atoi(num);
excl=strtok(NULL,NULL); k=strlen(excl);
while(coeff*k<n) { val=n-coeff*k; fact=fact*val; coeff++; }
if(n%k!=0) fact=fact*(n%k); else fact=fact*k;
printf("%ld",fact);
return 0; } Hi! I am getting runtime error(access violation) although the solution seems to work for different set of inputs. Please help me out! Re: Runtime error(access violation) http://ideone.com/1tNjl7I have corrected your solution. Even if fix Access violation, You are just WA#5 (Because of a logic error) Edited by author 21.07.2017 00:59 Re: Runtime error(access violation) Hi Mahilewets! Thanks a lot! I did correct the "Runtime error" but was getting a "Wrong answer" error due to the error in logic in the while condition. Your's is the right one. Just a query though(pardon my ignorance as I am new to this kind of stuff). How do you find the test cases for each problem apart from the one already given? Re: Runtime error(access violation) |
|
|