C++ Tutorial/Language Basics/Introduction

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Calculating with integer constants

<source lang="cpp">#include <iostream> using std::cout; using std::endl; int main() {

 cout << 1 + 2               << endl;  
 cout << 1 - 5                << endl;  
 cout << 1 - 2               << endl;  
 cout << 1 * 2               << endl;  
 cout << 1/3                  << endl;  
 cout << 1  3                << endl;  
 cout << 1  -3               << endl;  
 cout << -1  3               << endl;  
 cout << -1  -3              << endl;  
 cout << 1 + 2/1 - 5        << endl;  
 cout << (1 + 2)/(1 - 5)    << endl;  
 cout << 1 + 2/(1 - 5)      << endl;  
 cout << (1 + 2)/1 - 5      << endl;  
 cout << 4*5/3 + 7/3         << endl;  
 return 0;                               

}</source>

3
-4
-1
2
0
1
1
-1
-1
-2
0
1
-2
4

This is a simple C++ program

<source lang="cpp">#include <iostream> using namespace std;


int main() {

 cout << "www.java2s.com"; 

 return 0; 

}</source>

www.java2s.com"

Using the assignment operator

<source lang="cpp">#include <iostream> using std::cout; using std::endl; int main() {

 int a = 10;
 int b = 6;
 int c = 3;
 int d = 4;
 int f = (a + b)/(c + d);
 cout << f ;
 return 0;

}</source>

2

Working with integer variables

<source lang="cpp">#include <iostream> using std::cout; using std::endl; int main() {

 int a = 10;             
 int b = 3;            
 cout << a/b;
 cout << a  b;
 return 0;                    

}</source>

31