'합 출력'에 해당되는 글 1건

  1. 2021.02.14 [ 아두이노 ] 정수 2개 입력받아서 합 구하기 6
아두이노2021. 2. 14. 00:26
728x90

[ 코드 ]

int nState = 1;



void setup() {

  // put your setup code here, to run once:

Serial.begin(9600);

}

void loop() {

  // put your main code here, to run repeatedly:

if (nState){

  Serial.println("Enter 2 Integers to add");

  nState = 0;

}

while(Serial.available() == 0) {} //wait for input

int v1 = Serial.parseInt();



while(Serial.available() == 0) {}

int v2 = Serial.parseInt();



int sum = v1+v2;

Serial.print(v1);

Serial.print("+");

Serial.print(v2);

Serial.print("=");

Serial.println(sum);



nState = 1;

}

 

 

[ 결과 ]

 

※ 제 글이 도움이 되었다면 공감 부탁드려요 :)

반응형
Posted by mminky