/************************************************************************ * Section 15 * M/c No : M * Roll No : 18CS100XY * Names : Soumyajit Dey, Aritra Hazra * Problem No : LT1-EVEN-1 * Description : Program to output count-digit version of a given integer *************************************************************************/ #include #include int main() { unsigned int num; unsigned long int dupNum, countNum = 0; int i, digitCounter, matchFlag, powerTerm = 0; printf("Enter Non-zero Positive Integer: "); scanf("%d",&num); /* finding digits 1-9 in the given number and constructing the count-digit version of number */ for(i=9, powerTerm=1; i>=0; i--) { dupNum = num; digitCounter = 0; matchFlag = 0; while(dupNum!=0){ if(i == (dupNum%10)){ digitCounter++; matchFlag = 1; } dupNum = dupNum/10; } if(matchFlag){ /* two digits to be constructed for every match */ countNum = countNum + digitCounter*pow(10,powerTerm) + i*pow(10,powerTerm-1); /* incrementing the 10^ factor by two places */ powerTerm = powerTerm + 2; } } /* presenting the count-sigit version of the number */ printf("Count-Digit Version of Number: %lu\n", countNum); return 0; }