This question has already been answered:
- Spline number 2 replies
It is necessary to write each digit of a number into an array, and then add them up.
int n = 87654321; int size = IntCount(n);//к-во цифр в числе int array[size],i; // да, VLA лучше не использовать но так проще int stepen = size-1, // степень в какую возносим, самый старший разряд- [0] summa=0; for(i=0;i<size;i++) { array[i] = n/(int)pow(10,stepen)%10; //получаем каждую цифру и в массив summa=summa + array[i]; stepen--; // уменьшаем степень } printf("Сумма = %d",summa); As a result, the addition gives some nonsense, although the numbers in the array are correct. Perhaps the problem is in the modifier, but I do not understand why.