Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- int main()
- {
- int num; // 입력
- int sum = 0; // 자릿수 더할 변수
- int cnt = 0; // 반복횟수 == 자릿수
- printf("정수 입력 : ");
- scanf("%d", &num);
- while (num > 0)
- {
- // 123 % 10 == 3 | 12 % 10 == 2 | 1 % 10 == 1
- sum = sum + (num % 10);
- // 123 / 10 == 12 | 12 / 10 == 1 | 1 / 10 == 0
- num = num / 10;
- cnt++; // 1 | 2 | 3
- }
- printf("%d자리\n", cnt);
- printf("각 자리의 합은 %d\n", sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement