checking if number is pandigital

This code checks if number is pandigital (from 1 to 9). I have a few question to ask:

1. This code relies on theory that:
*if number digits product equals factorial of number length and
*if number digits sum equals summation of consecutive integers to length
then the number is pandigital.

Is there any proof for this?

Also, is it possible to somehow change the code so it considers number a pandigital even if one of it's digits is 0?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include <iostream>
using namespace std;

bool check(int number, int length) {
    int i=0;
    int grid[length];
    while (number>0) {
        grid[i]=number%10;
        number=number/10;
        i++;
    }
    int summation=0, factorial=1;
    int summation1=0, factorial1=1;
    for (int i=0; i<=length-1; i++) {
        factorial=factorial*grid[i];//counts product of digits and factorial of length
        factorial1=factorial1*(i+1);
        summation=summation+grid[i];//counts sum of digits and summation of integers to length
        summation1=summation1+(i+1);
    }
    if ((factorial==factorial1) and (summation==summation1) and (factorial!=0)) return true;
    else return false;
}

int main()
{
for (int i=1; i<=999999999; i++) {
        // counts how many digits there is
        int temp=i;
        int a=0;
        while (temp>0) {
            temp=temp/10;
            a++;
        }
        //checks if number is pandigital
    if (check(i, a)==true) {cout << i << endl;}
}
}
Topic archived. No new replies allowed.