c#/수업 내용

1/9 개수세기

yeeendy 2023. 1. 9. 12:09

최대값 구하기

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study07
{
    class App
    {
        //생성자
        public App()
        {
            Console.WriteLine("App생성자");
            
            //개수세기
            int[] arr = { 20, 10, 35, 30, 7 };
            int temp = arr[0];
            for(int i = 0; i < arr.Length; i++)
            {
                if (temp < arr[i])
                    temp = arr[i];
            }
            Console.WriteLine(temp);
        }
    }
}​

ㅡㅡㅡㅡㅡㅡㅡㅡ개수세기ㅡㅡㅡㅡㅡㅡㅡㅡㅡ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study07
{
    class App
    {
        //생성자
        public App()
        {
            Console.WriteLine("App생성자");

            //개수세기
            int[] arr = { 1, 3, 1, 3, 2, 3, 1, 4, 4, 5 };
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("input: {0}", n);
            int cnt = 0;
            for (int i = 0; i<arr.Length; i++)
                if (n == arr[i]) cnt++;
                Console.WriteLine("count:{0}",cnt);
            
        }


    }
}

 

'c# > 수업 내용' 카테고리의 다른 글

변하지 않는 데이터 만들기 연습 2 (Mission, Item)  (0) 2023.01.13
230113  (0) 2023.01.13
1/9 배열 연습(학생)  (0) 2023.01.09
배열  (0) 2023.01.06
값을 반환하기(ex, 총알 , 코인, 템플러 머지)  (0) 2023.01.06