MIPI_BaseC_WebinarFRTK/07_Lecture07/08_sum_p24.c

22 lines
300 B
C
Raw Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
//Нерекурсивный способ:
int sumIter(int num)
{
int sum = 0;
while(num > 0)
{
sum += num % 10;
num /= 10;
}
return sum;
}
int main()
{
int numb;
scanf("%d",&numb);
printf("%d\n",sumIter(numb));
return 0;
}