How to get the total numbers with no repeated digits from a range of two digit numbers in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

int GetTotalNumbersWithNoRepeatedDigitsTwoDigits(int start, int end) {
    int total_digits_minus_one = 1;

    int total = 0;
    for (int i = start; i <= end; i++) {
        int first_digit = (int)(i / pow(10, total_digits_minus_one));
        int last_digit = i % 10;

        if (first_digit != last_digit) {
            total++;
        }
    }

    return total;
}

int main()
{
    int start = 10, end = 45;

    printf("%d", GetTotalNumbersWithNoRepeatedDigitsTwoDigits(start, end));

    return 0;
}




/*
run:

32

*/

 



answered Jan 13, 2023 by avibootz
edited Jan 13, 2023 by avibootz
...