I spent 12 hours and i get o/p in dev c++ but wrong answer message here.

Thanks in advance.

#include

using namespace std;

int multiply(int *b,int m,int j)

{int sum[1000],c=0,l;

while(m>1)

{ for(int i=0;i<j;i++)

{

sum[i]=((b[i]*m)+c)%10;

c=((b[i]*m)+c)/10;

}

m–;

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

{

```
b[i]=sum[i];
}
```

}

for(l=j-1;sum[l]==0;l–)

{

}

for(int i=l;i>=0;i–)

{

cout<<sum[i];

}

return 0;

}

int main()

{int t;

cin>>t;

for(int v=0;v<t;v++)

{

int n,m,j=0;

int a[1000];

```
cin>>n;
```

if(n!=1&&n!=2)

{

```
m=n-1;
while(n!=0)
{
a[j]=n%10;
j++;
n=n/10;
}
while(j<170)
{
a[j]=0;
j++;
```

}

multiply(a,m,j);

}

else

{if(n==2)

cout<<2;

else

cout<<1;

}

}return 0;

}

sum[i]=((b[i]m)+c)%10;

```
c=((b[i]m)+c)/10;
```

You cannot write ab instead of a x b.

Check your above two lines…

Instead of writing b[i] x m , you worte b[i]m…

And at last please use correct format to ask a question as @betlista said so that it become easy to be read…!

Accepted version of your code: CodeChef: Practical coding for everyone

Also, you forgot to add newline after printing each value…

So, add

cout<< endl;

before return 0 in function multiply(), and add

<< endl;

after each cout statement in main().

1 Like

You shouldn’t write

```
b[i]m
```

.It is vague,instead write it as

```
b[i]*m
```

As the compiler needs to know the operation to be performed.

Thanks a lot @rishabhprsd7 and @ansh1star033. And definitely i will improve my formatting next time @betlista. I missed the endl statement.

Please use correct titles and format your code also… Get inspired here how to ask the question properly

Not really, it is formatting problem here in forum… * is special character… That’s why proper formatting is needed…

2 Likes

yes i realized that now… then fault may be due to ‘\n’ which i just updated in above post…

Thanks for pointing that out…

1 Like

You can still edit your question and if it helped, you can accept the answer and/or upvote…

Welcome

Now that’s How you learn while you code!!..

1 Like