finding the sum of a given Int but ignoring duplicate numbers

I can't use arrays or lists and I have to use C.

Duplicates mean if you have 975444579 it will show 25 or if you have 32111 it will show 6 and not 8. Here is my code:

#include <stdio.h>

int main() {
    int num = 0, sum = 0, i = 0, oNum = 0, nNum = 0, tNum = 0, e = 0;
    printf("enter a number: ");
    scanf("%d", &num);
    oNum = num;
    while (num != 0) {
        e = 0;
        i = 0;
        nNum = oNum;
        tNum = num % 10;
        do {
            if (nNum % 10 == tNum) {
                i += 1;
            }
            nNum /= 10;
        } while (nNum != 0);
        sum += tNum;
        i -= 1;
        while (e < i) {
            sum -= tNum;
            e += 1;
        }
        num /= 10;
    }
    printf("%d", sum);
    return 0;
}


from Recent Questions - Stack Overflow https://ift.tt/3pqIUeR
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)