Here is my code for PROBLEM FLOW007. Output is correct but it still says Wrong Answer on submitting.

``````int main()
{
int T, N, i, rev;
scanf("%d", &T);
int arr[T];
for(i=0;i<T;i++){
scanf("%d", &arr[i]);
}
for(i=0;i<T;i++){
while(arr[i]>=10){
rev=arr[i]%10;
printf("%d",rev);
arr[i]=arr[i]/10;
}
printf("%d\n", arr[i]);
}
}``````

In While Loop arry [i] should not be greater than 10. i.e
while(arr[i]<=10).
Try It.

Did you try out the actual test cases given and check that the output was an exact match for the expected output given? Because that doesn’t happen for your code above.

FLOW007, “Reverse The Number” has relatively friendly public test cases that exercise your code more fully. You will encounter plenty of challenges here where you have to anticipate edge cases that don’t occur in the given “worked” test set.

1 Like

I coded this in my own IDE, where it was providing me with the desired result. But it is marked as wrong on submitting. Please Help.
#include

using namespace std;

int rev(int n)

{

``````int n1, rem, rev=0, count=0;

n1=n;

while(n1--)

{

rem=n1%10;

n1/=10;

count++;

}

int arr[count];

for(int i=0; i<count; i++)

{

arr[i]=n%10;

n/=10;

}

for(int j=0; j<count; j++)

{

rem*=10;

rem+=arr[j];

}

return rem;
``````

}

int main()

{

``````int t, n;

cin>>t;

while(t--)

{

cin>>n;

cout<<rev(n)<<endl;

}

return 0;
``````

}

You have used variable rem before and you are reusing it again.It has already some value before entering the j loop. Just re-initialize rem = 0 before j loop .
The second and most important mistake is while(n1–) which doesn’t make any sense here. use while(n1!=0) , you will be good to go.