Last active
May 22, 2020 11:54
-
-
Save dalcon10028/91d9f8ebb2d398d5f48d06766904c32b to your computer and use it in GitHub Desktop.
Kaprika 수
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Kaprika 수 | |
| 네 자리 숫자 2025가 있을 때 두 자리씩 20, 25로 나눠서 합한 값인 45를 제곱하였을 때 값이 원래 수인 2025와 비교하는 문제 | |
| 2025를 예로 들면... | |
| 1. 20, 25으로 분리합니다. | |
| -> 2025 / 100 = 20 , 2025 % 100 = 25 | |
| 이때 프로그래밍 언어에서의 /,%는 숫자를 분리하는 용도로 사용할 수 있다는 걸 알아냅니다. | |
| 2. 두 값을 더해줍니다. | |
| -> 45 | |
| 3. 위에 과정을 한 번더 반복해 같은 값을 구합니다. ( 제곱의 기호가 없기 때문에 두 번 곱해줍니다. ) | |
| 4. 두 값을 곱해줍니다. | |
| -> 45 * 45 = 2025 | |
| 5. 원래 값과 일치하는지 비교합니다. | |
| -> 2025 == 2025 | |
| 6. 비교가 참이면 해당 값(인덱스 i)를 출력합니다. | |
| -> 2025는 Kaprika수 입니다. | |
| */ | |
| #include <stdio.h> | |
| int main() { | |
| int i; | |
| for (i=1000; i<10000; i++) // 1000~9999까지의 숫자를 확인해보기 위한 반복문 | |
| if((i%100+i/100)*(i%100+i/100) == i) // 분리 후 제곱한 값이 원래 값과 같은지 비교합니다. | |
| printf("%d는 Kaprika수 입니다.\n", i); // 참(원래값과 같다)일 경우 출력합니다. | |
| } | |
| /* | |
| 추가적으로 반복문 (for, do-while, while)과 조건문(if-else)문은 중괄호{}를 안쓸경우 | |
| 다음 세미콜론;이 나오기 전까지의 코드를 중괄호 안에 들어있다고 인식합니다. | |
| 다음 두 개의 코드는 동일하게 동작합니다. | |
| ex) | |
| while(1){ | |
| printf("하이"); | |
| } | |
| while(1) printf("하이"); | |
| 하지만 다음 두 개의 코드는 동일하게 동작하지 않습니다. | |
| while(1){ | |
| printf("하이"); | |
| printf("하이루루"); | |
| } | |
| while(1) | |
| printf("하이"); | |
| printf("하이루루"); | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment