본문 바로가기
개발 TIP/자료구조 && 알고리즘

약수와 동작시간 구하기

by izen8 2012. 1. 25.
반응형

public string Divisor(int diviValue)
{   
    int divCounter = 0;             // 나눈 갯수를 샘   
    int fcnt1 = 1;                 
    // for문에서 사용   
    int diviResult = 0;            
    // 나눈 나머지를 int형태로 저장   
    string divsResult = "";        
    // 나눈 나머지를 string형태로 저장   
    string resultStr = "";         
    // 반환할 최종 값을 저장   
    // diviValue = 입력된 정수    
    Stopwatch sw = new Stopwatch();   
    sw.Start();    
    for (fcnt1 = 1, divCounter = 0 ; fcnt1 <= diviValue; fcnt1++)   
    {       
        diviResult = diviValue % fcnt1;        
        if (diviResult == 0)       
        {           
            if (divCounter > 0)           
            {              
                divsResult = divsResult + string.Concat(", ");           
            }           
            divsResult = divsResult + string.Concat(fcnt1);           
            divCounter++;      
        }   
    }    
    sw.Stop();   
    resultStr = "Divisor of " + diviValue + " = " + divsResult + "\r\n"        + "Count : " + divCounter + "\r\n"        + "Process time : " + sw.Elapsed.ToString();    
    return resultStr;
}

반응형

'개발 TIP > 자료구조 && 알고리즘' 카테고리의 다른 글

지수 표기법 - 1E  (0) 2021.08.18
수학 사이트  (0) 2012.02.08
알고리즘 제공 사이트  (0) 2012.01.25
[유니코드] 한글 라이브러리  (0) 2012.01.10
휴대폰 정렬 알고리즘  (0) 2011.04.29

댓글