I do get the output right when i check it with custom input. But for some reason it still shows wrong answerhttps://www.codechef.com/viewsolution/29129978
1 Like
Not if you give it the Example Input from the problem statement, you don’t
[~/devel/hackerrank/otherpeoples]>echo "3
12345
31203
2123" | ./cringekid-FLOW006
6
6
5
1 Like
Try this…
#include
using namespace std;
int main() {
int t,i,temp,a,b[1000000];
cin>>t;
for(i=0;i<t;i++)
{
cin>>a;
temp=a;
//Edited by Atul Kumar
int ans=0;
while(temp>0)
{
ans=ans+(temp%10);
temp/=10;
}
b[i]=ans;
}
for(i=0;i<t;i++)
{
cout<<b[i]<<"\n";
}
return 0;
}
i think ur code adds 1st and last digit only
Oh my bad. I was actually looking for the answer to First and Last Digit question but i ended up typing the same code for Sum of Digits too.
1 Like
Actually this is the answer to First And Last Digits. I accidentally copied the same to FLOW006 and messed it up. I was looking for the solution to FLOW004