#include
int main()
{ int t;
std::cin>>t;
while(t–)
{
int n;
std::cin>>n;
int a[n];int i;
while(n>0)
{
a[i]=(n%10);
n/=10;
++i;
}
std::cout<<a[0]+a[i-1];
}
return 0;
}
The problem is FLOW004. What should I do to avoid runtime error?
Initialize i=0 before starting loop, otherwise the array goes out of bounds.
Please read this thread it might help you get better responses in the future.
1 Like
at the the time of declration of i,initialise with i=0; otherwise loop will never end.
1 Like