Problem of two nos..need help??

Whats wrong with my code…its showing runtime error…
#include<stdio.h>
int main()
{
long i,a,b,k,n,max=0,min=0;
int t;
scanf("%d",&t);
while(t–)
{
max=0;min=0;a=0;b=0;k=0;
scanf("%ld %ld %ld",a,b,n);
while(n<=30)
{
for(i=1;i<=n;i++)
{
if(i%2==0)
{
b=b2;
}
else
{
a=a
2;
}
}
if(a>b)
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
k=max/min;
printf("%ld",k);
}

}
return 0;
}

post the code link, it’s not clear here, or you can use Code Sample option to post your code.

The probable reason is you are not passing the address of a, b, and c in your scanf("%ld %ld %ld",a,b,n); statement. So the read integer is trying to get written in some random location which leads to a memory access violation error.

Update scanf() statement to

scanf("%ld %ld %ld",&a,&b,&n);

Also, variable a2, and b2 are not defined.

1 Like

Your code sample:

 scanf("%ld %ld %ld",a,b,n);

Modified one:

 scanf("%ld %ld %ld", &a, &b, &n);

Maybe this helps.

Happy coding!

1 Like
//