Hi, for the Problem Code:FLOW004
All sample test cases are running successfully when given as custom input but final submission shows Wrong answer.

I’m facing same issue for Problem Code:FCTRL2 .

Could anyone please help me here ?

my solution for the Problem Code:[FLOW004]-

#include < iostream>
using namespace std;

int main() {
// your code goes here

```
int t; int r;
cin>>t;
while(t--)
{ int sum=0;
int n;
cin>>n;
sum+=n%10;
n=n/10;
while(n!=0)
{ r=n%10;
n=n/10;
}
sum=sum+r;
cout<<sum<<"\n";
}
return 0;
```

}

my solution for Problem Code:FCTRL2

#include <iostream // plz ignore syntax error here
using namespace std;
int fact(int);
int main() {
// your code goes here

```
int t; int prod; int n;
```

// cout<<“before while”;

int facto[100];

```
cin>>t; int q=0;
while(t--)
{ //cout<<"inside while";
cin>>n;
facto[q++]= fact(n);
// cout<<p<<"\n";
}
for(int i=0;i<q;i++ )
{
cout<<facto[i]<<endl;
}
```

// cout<<“outside while”;

```
return 0;
```

}

int fact(int k)
{
int prod;
// cout<<“inside fact”;
if(k==1)
{ prod=1;}
else {
prod=1;
while(k>1)
{ prod*=k;
k–;

```
}
// return prod;
}
return prod;
```

}

For Problem FLOW004 , consider this test case.
Input

```
3
1
2
3
```

Expected Output

```
2
4
6
```

Your Output

```
1
2
3
```

And for problem FCTRL2 , you might want to look at this .

Factorials are very large.
0 : 1
1 : 1
2 : 2
3 : 6
4 : 24
5 : 120
6 : 720
7 : 5040
8 : 40320
9 : 362880
10 : 3628800
11 : 39916800
12 : 479001600
13 : 6227020800
14 : 87178291200
15 : 1307674368000
16 : 20922789888000
17 : 355687428096000
18 : 6402373705728000
19 : 121645100408832000
20 : 2432902008176640000
Factorial of 21 will not fit even in Unsigned long long int
You might want to share the problem link too. I tried finding the problem from your recent activity, but …

your code doesn’t work for single digit inputs.
Your corrected code: Link

sum+=n%10;
n=n/10;

Consider the second line, it changes original number to 0 for single digit inputs.
hope you got it.

hi,
this is my updated code but still getting WA. Could you see problem in this version ? Thanks

#include
using namespace std;
int summ(int);

int main() {
// your code goes here

```
int t; int r; int ans[1000]; int p=0;
cin>>t;
while(t--)
{ int sum=0;
int n;
cin>>n;
ans[p]=summ(n);
p++;
}
for(int i=0; i<p;i++)
{
cout<<ans[i]<<"\n";
}
return 0;
```

}

int summ(int a)
{
int rsum=a%10;
a=a/10;
int r=0;
while(a!=0)
{ r=a%10;
a=a/10;

```
}
rsum+=r;
return rsum;
```

}

Hi,
problem statement here says to print sum of 1st and last digit so for the case of single digits answer should be same as number entered.

Could you plz explain how come output for 1 2 3 is 2 4 6 but not 1 2 3.

problem link: FLOW004 Problem - CodeChef

It’s the conclusion I drew from other Accepted submissions

I have already updated the earlier version of your code to give AC.

For single digits numbers, that number itself accounts the 1st and last digit.
so, for 1, the output shall be 1+1=2 , not 1
Similarly for the other numbers.

ohh I get it now, I wasn’t taking single digit twice to make up for both the first and last digit.

Thank you @manvi_03

1 Like