I have been working on this code for 3 days now and I can't figure out how to remove zeros before the output.
It is a program which calculates factorial of a number. Even if I use if statement as you can see which is commented it removes zeros after and between the numbers. I even tried to take size as the initial value for a but it just takes the global value, but not from the while loop, I even tried to store its value in another variable then also its not working.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// Complete the extraLongFactorials function below.
void extraLongFactorials(int n) {
  int arr[500] = {0};
  int size = 1, i = 0, carry = 0, temp = 0;
  arr[0] = 1;
  for (int j = 1; j <= n; j++) {
    for (int k = 0; k < 500; k++) {
      temp = arr[k] * j + carry;
      arr[k] = temp % 10;
      carry = temp / 10;
    }
    while (carry) {
      size++;
      arr[size] = carry % 10;
      carry %= 10;
    }
  }
  for (int a = 499; a >= 0; a--) { // if(arr[a]!=0)
    cout << arr[a];
  }
}
int main() {
  int n;
  cin >> n;
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  extraLongFactorials(n);
  return 0;
}
 
     
    