Skip to content

Instantly share code, notes, and snippets.

@Shravan40
Created July 13, 2013 06:16
Show Gist options
  • Save Shravan40/5989627 to your computer and use it in GitHub Desktop.
Save Shravan40/5989627 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t,n,i,m;
cin>>t;
while(t--)
{
cin>>n;
m = n;
int size = 0 , i = 0, temp = 0, prod;
int arr [200];
while(n != 0)
{
temp = n % 10;
arr[i] = temp;
n /= 10;
size++, i++;
}
temp = 0;
m -= 1;
while(m > 0)
{
for(i = 0; i < size; i++)
{
prod = arr[i] * m + temp;
arr[i] = prod % 10;
temp = prod / 10;
}
while(temp != 0)
{
arr[i] = temp % 10;
temp /= 10;
size++, i++;
}
m--;
}
for (i = size-1; i >= 0; i--)
{
cout<<arr[i];
}
cout<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment