-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-Operadores-22jun2019.cpp
More file actions
130 lines (95 loc) · 1.89 KB
/
06-Operadores-22jun2019.cpp
File metadata and controls
130 lines (95 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//Prof Marcos Castro
//Curso de C++ Intermediário
//Udemy
//Aula 6
//Operadores em C++
//Concluído em 22 jun 2019
#include <iostream>
using namespace std;
int main()
{
float n1,n2,soma, produto, division;
n1= 10;
n2=20;
int n3,n4,resto,subtr;
n3=20;
n4=10;
//+ atua como operador binário
//pois atua sobre dois argumentos
//que são n1 e n2
soma = n1+n2;
cout <<soma;
cout<<" "<<endl;
//multiplicação
produto = n1*n2;
cout<<" "<<endl;
cout <<produto <<endl;
//divisão
division = n1/n2;
cout<<" "<<endl;
cout <<division <<endl;
//resto
resto = n4%n3;
cout<<" "<<endl;
cout <<resto <<endl;
//subtração
subtr = n3-n4;
cout<<" "<<endl;
cout <<subtr <<endl;
//operadores unários:
//pós-incremental
int s = 10;
//contador via unidade, como o velho let s= s+1
s++;
cout <<""<<endl;
cout<<s <<endl;
//decremental
//ou o velho let x = x-1
int x = 24;
x--;
cout <<""<<endl;
cout<<x <<endl;
float k=77;
//aqui é o velho step 7
k +=7;
cout <<""<<endl;
cout<<k<<endl;
//e o velho step -7
k -=7;
cout <<""<<endl;
cout<<k<<endl;
// let k = k*2 (pg multiplicando por 2)
k *=2;
cout<<k<<endl;
//let k = k/5 (pg dividindo por 5)
k /=5;
cout <<""<<endl;
cout<<k<<endl;
//pré-incremental
int z = 222;
++z;
cout <<""<<endl;
cout <<z;
cout <<""<<endl;
//outra dica de pré-incremento
int nr1 = 30;
int nr2 = ++nr1;
cout <<""<<endl;
cout <<nr2;
// e da mesma forma com "--z", "*", "/" etc
//mudando precedências de operações matemáticas
int m;
m = 10+20/2;
cout <<""<<endl;
cout <<m;
//ela ocorre com o uso dos parêntesis
m = (10+20)/2;
cout <<""<<endl;
cout <<m<<endl;
//mudança de sinal de um número
int inv= 10;
int inv2= -inv;
cout <<""<<endl;
cout<<inv2<<endl;
return 0;
}