투케이2K

40. (C++) abs 사용해 절대값 확인 실시 본문

C++

40. (C++) abs 사용해 절대값 확인 실시

투케이2K 2023. 3. 6. 20:39
반응형

[개발 환경 설정]

개발 언어 : C++

 

[소스 코드]

// -----------------------------------------------------------------------------------------
//
// Created by KGH on 2023-02-12.
//
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [헤더 파일 import]
#include <jni.h>
#include <android/log.h>
#include "Test.h"
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [include 및 define 문 정의]
#include <iostream>
#include <string>
using namespace std;
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [구현부 소스 코드 작성]
int main(void)
{


    /**
     * ------------------------------------
     * [요약 설명]
     * ------------------------------------
     * 1. abs : 정수 절대값을 출력해줍니다
     * ------------------------------------
     * */


    // [변수 선언]
    int origin_one = -1;
    int origin_two = 2;


    // [abs 사용해 절대값 확인 실시]
    int abs_one = abs(origin_one);
    int abs_two = abs(origin_two);


    // [로그 출력 실시]
    __android_log_print(ANDROID_LOG_WARN, "[C++] [LOG]", "%s", "=====================================================");
    __android_log_print(ANDROID_LOG_INFO, "[C++] [LOG]", "[abs_one] :: %d", abs_one);
    __android_log_print(ANDROID_LOG_INFO, "[C++] [LOG]", "[abs_two] :: %d", abs_two);
    __android_log_print(ANDROID_LOG_WARN, "[C++] [LOG]", "%s", "=====================================================");

    return 0;
}
// -----------------------------------------------------------------------------------------
 

[결과 출력]

 

W/[C++] [LOG]: =====================================================
I/[C++] [LOG]: [abs_one] :: 1
I/[C++] [LOG]: [abs_two] :: 2
W/[C++] [LOG]: =====================================================

 

반응형
Comments