본문 바로가기

프로그램/C# 1000제34

C# 25제] C# 프로그램 입문 CHAPTER 3. p151 3.9 (12) 마방진 구하는 프로그램을 작성하시오. 출처 : 반크 카드뉴스 문제] 하나의 홀수를 읽어 그에 해당하는 마방진(magic square)을 구성하는 프로그램을 작성하시오. 마방진은 가로, 세로, 대각선에 있는 수들의 합이 모두 같은 정방형 메트릭스를 말한다. 다음은 3을 입력으로 받아 만들어진 3X3 마방진이다. 8 1 6 3 5 7 4 9 2 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P151_3_9_12 { public static void Main(String[] args) { int N;//마방진 수 입력변수 int r, c;//행,열변수 int cnt;//증가값 변수 //마방진 수을 입력받는다. 마방진.. 2021. 9. 3.
C# 24제] C# 프로그램 입문 CHAPTER 3. p151 3.9 (11) 행열을 바꾸는 프로그램을 작성하시오. 출처 : 반크 카드뉴스 문제] 행렬의 행과 열을 바꾸는 메소드인 transpose를 작성하고, 다음 데이터를 이용하여 테스크하시오. 1 2 3 4 5 6 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P151_3_9_11 { public static int[,] transpose(int[,] P1) { int i,j;//P1의 행열변수 int[,] P2 = new int[P1.GetLength(1),P1.GetLength(0)]; //행열을 맞바꾸기 for (i = 0; i 2021. 9. 1.
C# 23제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (10) 거스름돈 최소 개수를 구하는 프로그램을 작성하시오. 출처 : 반크 카드뉴스 문제] 1원, 5원, 10원, 50원, 100원, 500원 짜리 동전을 충분히 갖고 있는 상점이 있다. 고객이 1000원 미만의 물건을 사고 1000원 짜리 돈을 냈을 때 거스름돈을 동전의 개수가 최소가 되도록 계산하는 C# 프로그램을 작성하시오. 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_10 { public static void Main(string[] args) { int[] don = { 500, 100, 50, 10, 5, 1 };//동전금액 int[] change = new int[6];//동전금액의 개수를 넣을 변수 i.. 2021. 8. 31.
C# 22제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (9) ③ 아래와 같이 출력하는 프로그램을 작성하시오. 출처 : 반크 카드뉴스 참고풀이 결과] 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_9_3 { public static void Main(string[] args) { int r, c;//행열변수 //수나열하기 for(r=1;r 2021. 8. 30.
C# 21제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (9) ② 아래와 같이 출력하는 프로그램을 작성하시오. 출처 : 반크 카드뉴스 참고풀이 결과] 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_9_2 { public static void Main(string[] args) { int r, c;//행열변수 int n;//수 출력변수 //수 삼각형 출력하기 for(r=1;r 2021. 8. 30.
C# 20제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (9) ① 아래와 같이 출력하는 프로그램을 작성하시오. 출처 : 반크 카드뉴스 참고풀이 결과] 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_9_1 { public static void Main(string[] args) { int r, c;//행열변수 int n1,n2;//열 빈칸/별 출력 변수 //마름모 별 출력하기 for (n1=-1,n2=5,r = 1; r 2021. 8. 30.
C# 19제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (8) 아래와 같이 구구단을 출력하는 프로그램을 작성하기 출처 : 반크 카드뉴스 참고풀이 결과] 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_8 { public static void Main(string[] args) { int dan;//단변수 int i;//반복변수 int c;//단 가로출력체크 변수 int k;//단 세로출력체크 변수 //구구단 출력하기 for(k=1;k 2021. 8. 30.
C# 18제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (7)② 수식의 결과값을 구하는 프로그램을 작성하기 출처 : 대한민국 외교부 독도갤러리 문제] 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_7_2 { public static void Main(string[] args) { int i;//반복변수 int sw;//부호 switch변수 double S;//수식 ∑연산 결과값 변수 //수식에 맞게 처리한다. … sw = 1; S = 0.0; for (i = 1; i 2021. 8. 27.
C# 17제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (7)① 수식의 결과값을 구하는 프로그램 작성하기 출처 : 대한민국 외교부 독도갤러리 문제] S = 1 + (1*2) + (1*2*3) + (1*2*3*4) + ··· + (1*2*3* ··· *10) 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P150_3_9_7_1 { public static void Main(string[] args) { int i;//반복변수 int N;//반복변수 int S;//수식 ∑연산 결과값 변수 int M;//수식 ∏연산 결과값 변수 //수식에 맞게 처리한다. S = 0; for (N = 1; N 2021. 8. 27.
C# 16제] C# 프로그램 입문 CHAPTER 3. p150 3.9 (6) 수식의 결과값을 구하는 프로그램 작성하기 출처 : 대한민국 외교부 독도갤러리 문제] 다음 식을 계산하는 C#프로그램을 작성하시오. 참고풀이] using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; namespace Chapter3 { class P150_3_9_6 { public static void Main(string[] args) { int i;//반복변수 int S;//수식 ∑연산 결과값 변수 int M;//수식 ∏연산 결과값 변수 //수식에 맞게 처리한다. S = 0; for (i = 1; i 2021. 8. 26.
C# 15제] C# 프로그램 입문 CHAPTER 3. p149 3.9 (5) 최대공약수와 최소공배수 구하기 출처 : 대한민국 외교부 독도갤러리 문제] 두 수를 입력으로 받아 최대 공약수와 최소 공배수를 구하는 프로그램. 참고풀이] using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; namespace Chapter3 { class P149_3_9_5 { public static void Main(string[] args) { //두 수를 입력하여 최대공약수와 최소 공배수를 구하는 프로그램 int X, Y;//두 수 입력변수 int G;//최대공약수 변수 int L;//최소공배수 변수 int MIN; int r; //두 수를 입력받는다. Console.Write("첫.. 2021. 8. 25.
C# 14제] C# 프로그램 입문 CHAPTER 3. p149 3.9 (4) 암스트롱수 출력하기 출처 : 대한민국 외교부 독도갤러리 문제] 암스트롱수(Armstrong number)란 3개의 숫자로 구성되며 각 자릿수에 있는 숫자의 세제곱의 합이 자신과 같은 수이다. 100부터 500사이의 암스트롱수를 구하는 프로그램 XYZ=X*X*X + Y*Y*Y 참고풀이] using System; using System.Collections.Generic; using System.Text; namespace Chapter3 { class P149_3_9_4 { static void Main(string[] args) { int n;//100~500사이의 수로 암스트롱수 대상 변수 int X,Y,Z;//각자리수 변수 //100~500까지 반복하여 암스트롱수를 구한다. Console.WriteLine("100~50.. 2021. 8. 23.
반응형