include iostream using namespace std int main int

  • Slides: 26
Download presentation
#include <iostream> using namespace std; int main() { int number = 65; cout <<

#include <iostream> using namespace std; int main() { int number = 65; cout << number << endl; cout << static_cast<char>(number) << endl; return 0; }

#include <iostream> using namespace std; int main() { int length, width, area; cout <<

#include <iostream> using namespace std; int main() { int length, width, area; cout << "This program calculates the area of a "; cout << "rectangle. n"; cout << "What is the length of the rectangle? "; cin >> length; cout << "What is the width of the rectangle? "; cin >> width; area = length * width; cout << "The area of the rectangle is " << area << ". n"; return 0; }

#include <iostream> using namespace std; int main() { int length, width, area; cout <<

#include <iostream> using namespace std; int main() { int length, width, area; cout << "This program calculates the area of a "; cout << "rectangle. n"; cout << "Enter the length and width of the rectangle "; cout << "separated by a space. n"; cin >> length >> width; area = length * width; cout << "The area of the rectangle is " << area << endl; return 0; }

#include <iostream> using namespace std; int main() { int whole; double fractional; char letter;

#include <iostream> using namespace std; int main() { int whole; double fractional; char letter; cout << "Enter an integer, a double, and a character: "; cin >> whole >> fractional >> letter; cout << "whole: " << whole << endl; cout << "fractional: " << fractional << endl; cout << "letter: " << letter << endl; return 0; }

#include <iostream> #include <string> using namespace std; int main() { string name; string city;

#include <iostream> #include <string> using namespace std; int main() { string name; string city; cout << "Please enter your name. " << endl; cin >> name; cout << "Please enter the city you live in. " << endl; cin >> city; cout << "Hello, " << name << endl; cout << "You live in " << city <<endl; return 0; }

논리 연산자 (Logical Operators) n 논리 연산을 수행한다. bool b 1 = true; bool

논리 연산자 (Logical Operators) n 논리 연산을 수행한다. bool b 1 = true; bool b 2 = false; bool and bool or bool not n = b 1 && b 2; = b 1 || b 2; = ! b 1; 피연산자를 사용해서 부울 연산을 수행한다. 피연산자 1 false 피연산자 2 false AND(&&) false OR(||) false NOT(!) true false true true false * NOT 연산자는 피연산자 1 만 받는다.

#include <iostream> using namespace std; int main() { // 모든 경우의 AND 연산 수행

#include <iostream> using namespace std; int main() { // 모든 경우의 AND 연산 수행 bool b 1, b 2, b 3, b 4; b 1 = false && false; b 2 = false && true; b 3 = true && false; b 4 = true && true; // 결과를 출력 cout << boolalpha; cout << "false AND false ---> " << b 1 << "n"; cout << "false AND true ---> " << b 2 << "n"; cout << "true AND false ---> " << b 3 << "n"; cout << "true AND true ---> " << b 4 << "n"; return 0; }

#include <iostream> using namespace std; int main() { // !연산자의 사용 bool b 1,

#include <iostream> using namespace std; int main() { // !연산자의 사용 bool b 1, b 2; b 1 = !true; b 2 = !false; // 결과 출력 cout << boolalpha; cout << "NOT true --> " << b 1 << "n"; cout << "NOT false --> " << b 2 << "n"; return 0; }

#include <bitset> #include <iostream> using namespace std; int main() { // 다양한 타입의 변수를

#include <bitset> #include <iostream> using namespace std; int main() { // 다양한 타입의 변수를 준비한다. short int si = 2; int i = 4; // 각각 2진수와 10진수로 출력한다. cout << "si = " << bitset<16>(si) << "(" << si << ")n"; cout << "i = " << bitset<32>(i) << "(" << i << ")n"; return 0; }

01 02 03 04 05 06 07 08 09 #include<iostream> using namespace std; void

01 02 03 04 05 06 07 08 09 #include<iostream> using namespace std; void main( ) { short int x = 15; cout << "x << 2 cout << "x >> 2 } : " << (x << 2) << "n"; : " << (x >> 2) << "n";

01 02 03 04 05 06 07 08 09 10 11 12 13 14

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 #include<iostream> using namespace std; void main( ) { int a , b , c; int max; cout << " 세 수를 입력하세요 : "; cin >> a >> b >> c; max = (a > b) ? a : b; max = (max > c) ? max : c; } cout << " 가장 큰 수는 : " << max <<"n";

#include <bitset> #include <iostream> using namespace std; int main() { unsigned int a, b;

#include <bitset> #include <iostream> using namespace std; int main() { unsigned int a, b; a = 178; b = 113; // 비트단위 논리 연산을 수행 unsigned int c 1, c 2, c 3, c 4; c 1 = a & b; // AND c 2 = a | b; // OR c 3 = a ^ b; // XOR c 4 = ~a; // NOT // 결과를 출력한다. 괄호안에는 10진수가 출력된다. cout << "a = " << bitset<8>(a) << "(" << (int)a << ")n"; cout << "b = " << bitset<8>(b) << "(" << (unsigned int)b << ")n"; cout << "a & b = " << bitset<8>(c 1) << "(" << (unsigned int)c 1 << ")n"; cout << "a | b = " << bitset<8>(c 2) << "(" << (int)c 2 << ")n"; cout << "a ^ b = " << bitset<8>(c 3) << "(" << (int)c 3 << ")n"; cout << "~a = " << bitset<8>(c 4) << "(" << (int)c 4 << ")n"; return 0; }