전체 글 226

C# Loop : 반복문 01

foreach 향상된 for문을 통해 반복 가능한 자료형의 반복을 쉽게 하도록 해줌 인자로 들어온 itrable-item의 내부 인덱스 끝까지 반복 foreach(데이터형식 변수명 in 배열명){ } 예제 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Loop_01 { internal class Loop_01 { static void Main(string[] args) { //반복문 //for, while, do-while c언어와 문법 동일 //foreach 향상된 for문 string[] arr = { "홍길동", "김길동"..

C#/C# Basic 2022.12.03

C# 기본

namespace 하는 일이 비슷한 클래스, 구조체, 인터페이스 , 델리케이트 열거 형식 등을 하나의 이름 아래 묶는 역할 충돌 방지를 목적 namespace example{ internal class Program { static void Main(string[] args) { } } } Class C#프로그램을 구성하는 기본 단위 데이터 + 메소드로 구성됨 Class 안에서 변수 선언 , 함수를 사용한다 C#은 최소 하나 이상의 클래스로 이루어진다 internal class는 내부 클래스 뜻함 주석 스타일 1. /**/ 블록 주석 2. // 한줄주석 3. /// 메소드 주석 - 꼭 그런 건 아니다 /// /// 함수에 대한 정보를 이곳에 설명한다 /// /// 변수 네이밍 스타일 1. 스네이크 방식 ..

C#/C# Basic 2022.12.02

Array : reverse order (역순)

문제 10 배열요소의 순서를 역순으로 표시하는 프로그램을 작성하시오 역시 Math.Random메서드를 이용하여 먼저 해당하는 배열에 랜덤값으로 치환하고 그것을 출력하고 역순으로 출력하시오. 실행결과 요소수 : 3 사용자로부터 입력 a[0] = 22 a[1] = 57 a[2] = 11 위의 배열을 역순 출력함. a[0] = 70 a[1] = 68 a[2] = 91 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Array_10 { internal class Array_10 { static void Main(string[] args)..

C#/C# 연습 2022.11.30

Array : Random Number (난수), Coin (동전 개수)

문제 8 실행결과와 같이 되도록 프로그램을 작성하시오. int[] code {-9, -55, 73, 116, 101, 205, 1000}초기화 조건 : arr배열의 값들은 code배열에 있는 값으로만 존재함 아울러, 난수를 발생시켜 대입토록 한다. 실행결과 출력되는 값은 code배열에 있는 값으로만 구성됨 arr배열 값 출력 [-55, 1000, 1000, -9, 73, -9, 116, -55, 1000, 1000] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Array_08 { internal class Program { s..

C#/C# 연습 2022.11.30

Array : Sort, Reverse (정렬)

문제 7 실행결과와 같이 되도록 프로그램을 작성하시오. 조건 : 배열의 i번째 요소와 임의의 요소에 저장된 값을 서로 바꿔서 값을 섞은 후 내림차순으로 정렬 후 0~5번 인덱스의 값만 출력하도록 한다. 실행결과 0~19번 방까지의 값 출력 ball[0]=1 ball [1]=2 ball [2]=3 ball [3]=4 ... ball배열의 앞에서부터 6개만 출력(값을 섞은 후, 내림차순 소팅한 결과) ball [0]=20 ball [1]=19 ball [2]=18 ball [3]=17 ball [4]=16 ball [5]=15 using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography;..

C#/C# 연습 2022.11.30

Array : Combine, Random (섞기, 랜덤)

문제 5 아래의 실행결과가 나오도록 프로그램을 작성하시오. 타입 변수명 설명 int[] numArr 10개의방 생성 조건 : 값을 섞는다 실행결과 원래의 배열 값들을 출력 0,1,2,3,4,5,6,7,8,9 값을 임의로 섞은후 출력 0,4,9,3,5,6,2,8,7,1 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace pr_array_02 { internal class Program { static void Main(string[] args) { Random rand = new Random(); int[] arr = new int[1..

C#/C# 연습 2022.11.29

Array : Input, MaxMin (입력, 최대값 최소값)

문제3 배열의 요소 수와 각 요소의 값을 입력하면 실행결과와 같이 각 요소의 값을 표시하는 프로그램을 작성하시오. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace pr_array_02 { internal class Program { static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); int[] arr = new int[input]; for (int i = 0; i < arr.Length; i++) { arr[i] = int.Parse(Consol..

C#/C# 연습 2022.11.29

Array : Length input, Random (배열수 입력, 난수)

문제 1 배열수를 입력받아 초기화하여 값을 출력하시오 실행결과 배열수 입력:10 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace pr_array_01 { internal class Program { static void Main(string[] args) { Console.WriteLine("배열수를 입력"); int input = int.Parse(Console.ReadLine()); int [] array = new int[input]; for (int i = 0; i < array.Length; i++) { Console.W..

C#/C# 연습 2022.11.28