Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Small Factorials problem solution

YASH PAL, 31 July 2024
In this HackerEarth Small Factorials problem solution, You are asked to calculate factorials of some small positive integers.
HackerEarth Small Factorials problem solution

HackerEarth Small Factorials problem solution.

#include<bits/stdc++.h>



#define ll long long
#define ull unsigned long long
#define repA(i,a,n) for(int i=a;i<n;i++)
#define repD(i,a,n) for(int i=n-1;i>=a;i--)

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)



using namespace std;
#define MAX 500
int res[MAX];

int multiply(int x, int res[], int res_size);

void factorial(int n)

{

res[0] = 1;

int res_size = 1;
for (int x=2; x<=n; x++)

{

res_size = multiply(x, res, res_size);

}



for (int i=res_size-1; i>=0; i--)

cout << res[i];

}



int multiply(int x, int res[], int res_size)

{

int carry = 0;



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

{

int prod = res[i] * x + carry;

res[i] = prod % 10;

carry = prod/10;

}



while (carry)

{

res[res_size] = carry%10;

carry = carry/10;

res_size++;

}

return res_size;

}



int main(){

fast;

int t;
cin>>t;
while(t--){



int n;
cin>>n;
factorial(n);
cout<<"n";

}

}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes