공부95 건축 평면도 연습 2022. 5. 11. 자릿수 분리하기 자연수 n이 주어지면, n의 자릿수를 분리하여 더한 값을 Console 창에 출력하는 코드를 만들어보세요. 예) n = 512면 5 + 1 + 2 = 8 8이 Console 창에 나오면 됩니다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class DivideNumber : MonoBehaviour { // Start is called before the first frame update void Start() { int n = 512; int answer = 0; while (n > 0) { // n을 10으로 나눈 나머지를 answer에 더한다. answer += n % 10; // n을 1.. 2022. 5. 11. 직삼각형 그리기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class DrawTriangle : MonoBehaviour { // Start is called before the first frame update void Start() { // * // ** // *** // **** // ***** string triangle = ""; for (int i = 0; i < 5; i++) { // 별을 추가한다. for (int j = 0; j < i + 1; j++) { triangle += "*"; } // 엔터를 추가한다. triangle += "\n"; } // 출력한다. print(triangle); .. 2022. 5. 11. 함수 연습 using System.Collections; using System.Collections.Generic; using UnityEngine; // 더하기 기능을 만들고 // 함수 구현부 int Plus(int a, int b) { return a + b; } public class AddFunc : MonoBehaviour { // Start is called before the first frame update void Start() { // 그 기능을 이용해서 값을 더한 후 int result = Plus(10, 20); // 출력하고싶다. print(result); } // Update is called once per frame void Update() { } } 2022. 5. 11. 수 더하기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class AddNumber : MonoBehaviour { // Start is called before the first frame update void Start() { // 1부터 10까지 다 더한 후 화면에 출력하고싶다. int number = 0; for (int i = 0; i < 10; i++) { number += i+1; } print(number); // 1부터 100까지 반복하고싶다. for (int i = 0; i < 100; i++) { // 만약 i가 짝수인 정수라면 if (i % 2 == 0) { // i를 출력하고싶다. p.. 2022. 5. 11. 이전 1 ··· 13 14 15 16 다음