C++ 문법 강의 내용 정리

2019. 1. 20. 17:00

==> 알고리즘 문제 풀이시 문법이 헷갈리지 않을 만큼만 목표로 하자.


#include<iostream>  // 기본 임포트


#include <bits/stdc++.h>   // 알고리즘 문제 풀이시 보통 많이 임포트 한다.


using namespace std;




간단한 입출력 방법


cout << "출력 " << endl ;  // 줄바꿈



cin >> i  // 입력





if 문 


#include <bits/stdc++.h>   // 알고리즘 문제 풀이시 보통 많이 임포트 한다.


using namespace std;


int main()


{


int x;

cout << "숫자를 입력해 주세요 : " ;

cin >> x;


if(x > 5)

{

cout << "5 보다 크다." << endl;

}

else 

{

cout << "5보다 작다." << endl;

}


}




while 문


int main()


{


cout << "while-loop test" << endl;


int count = 0; 

while (count < 10)

{

cout << count << endl;

++count;

}

return 0 ;


}


무한 루프는 

 while(True)




do - while 문


int main()

{

int sel;

do 

{

cout << " 무조건 한번을 실행하는 문자입니다. " << endl;

cout << " 1. aa " << endl;

cout << " 2. bb " << endl;

cout << " 3. cc " << endl;

cin >>  sel;

} while (sel <=0 || sel >= 3 );

cout << "you selected " << sel << endl;

return 0;

}




for 문


int main()

{

for (int count = 0; count < 10 ; count++)

{

cout << count << endl;

}

return 0 ;

}



http://ddmix.blogspot.com/2014/12/cppalgo-4-array-maze.html




+ Recent posts