SHARE
TWEET

Untitled

a guest Aug 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.     int num;        // ์ž…๋ ฅ
  7.     int sum = 0;    // ์ž๋ฆฟ์ˆ˜ ๋”ํ•  ๋ณ€์ˆ˜
  8.     int cnt = 0;    // ๋ฐ˜๋ณตํšŸ์ˆ˜ == ์ž๋ฆฟ์ˆ˜
  9.    
  10.     printf("์ •์ˆ˜ ์ž…๋ ฅ : ");
  11.     scanf("%d", &num);
  12.  
  13.     while (num > 0)
  14.     {
  15.         // 123 % 10 == 3    |   12 % 10 == 2    |   1 % 10 == 1
  16.         sum = sum + (num % 10);
  17.         // 123 / 10 == 12   |   12 / 10 == 1    |   1 / 10 == 0
  18.         num = num / 10;
  19.         cnt++;      // 1 | 2 | 3
  20.     }
  21.  
  22.     printf("%d์ž๋ฆฌ\n", cnt);
  23.     printf("๊ฐ ์ž๋ฆฌ์˜ ํ•ฉ์€ %d\n", sum);
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top