Professional Documents
Culture Documents
RAV2 - RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
Direto ao Assunto
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
display
teclado
atribuio
Estrutura bsica
se simples
se composto
para
ses encadeados
enquanto
faca enquanto
RAV2 RAV3
ALGORITMOS
se composto
ses encadeados
UAL
se simples
RAV2 RAV3
ALGORITMOS
enquanto
UAL
faca enquanto
se simples
se composto
para
RAV2 RAV3
ALGORITMOS
se composto
ses encadeados
Portugol
se simples
RAV2 RAV3
ALGORITMOS
escolha
Portugol
RAV2 RAV3
ALGORITMOS
enquanto
Portugol
faca enquanto
para
RAV2 RAV3
ALGORITMOS
se composto
ses encadeados
se simples
RAV2 RAV3
ALGORITMOS
switch()
RAV2 RAV3
ALGORITMOS
while
for
do while
RAV2 RAV3
ALGORITMOS
ALGORITMOS
Praticando
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ double a,b,c;
cout<<"\n1o numero:
cout<<"\n2o numero:
cout<<"\n3o numero:
if( a > b && a > c )
cout<<a<<"\n";
else if( b > c )
cout<<b<<"\n";
else
cout<<c<<"\n";
system("pause");
}
Dois menores
";
";
";
cin>>a;
cin>>b;
cin>>c;
Menor
Dois maiores
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ double a,b,c;
cout<<"\n1o numero:
cout<<"\n2o numero:
cout<<"\n3o numero:
if( a > b && a > c )
cout<<a<<"\n";
else if( b > c )
cout<<b<<"\n";
else
cout<<c<<"\n";
system("pause");
}
Dois menores
";
";
";
cin>>a;
cin>>b;
cin>>c;
cout<<b<<"\t"<<c<<"\n";
cout<<a<<"\t"<<c<<"\n";
cout<<a<<"\t"<<b<<"\n";
Menor
Dois maiores
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ double a,b,c;
cout<<"\n1o numero:
cout<<"\n2o numero:
cout<<"\n3o numero:
if( a > b && a > c )
cout<<a<<"\n";
else if( b > c )
cout<<b<<"\n";
else
cout<<c<<"\n";
system("pause");
}
Dois menores
";
";
";
cin>>a;
cin>>b;
cin>>c;
Menor
if( a < b && a < c )
else if( b < c )
Dois maiores
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ double a,b,c;
cout<<"\n1o numero:
cout<<"\n2o numero:
cout<<"\n3o numero:
if( a > b && a > c )
cout<<a<<"\n";
else if( b > c )
cout<<b<<"\n";
else
cout<<c<<"\n";
system("pause");
}
Dois menores
";
";
";
cin>>a;
cin>>b;
cin>>c;
Menor
Dois maiores
cout<<b<<"\t"<<c<<"\n";
cout<<a<<"\t"<<c<<"\n";
cout<<a<<"\t"<<b<<"\n";
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ double a,b,c;
cout<<"\n1o numero:
cout<<"\n2o numero:
cout<<"\n3o numero:
if( a > b && a > c )
cout<<a<<"\n";
else if( b > c )
cout<<b<<"\n";
else
cout<<c<<"\n";
system("pause");
}
Dois menores
";
";
";
cin>>a;
cin>>b;
cin>>c;
cout<<b<<"\t"<<c<<"\n";
cout<<a<<"\t"<<c<<"\n";
cout<<a<<"\t"<<b<<"\n";
Menor
if( a < b && a < c )
else if( b < c )
Dois maiores
cout<<b<<"\t"<<c<<"\n";
cout<<a<<"\t"<<c<<"\n";
cout<<a<<"\t"<<b<<"\n";
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;
int main()
{
char letra;
cout<<"\nDigite letra do Sistema Romano: ";
cin>>letra;
letra=toupper(letra);
RAV2 RAV3
ALGORITMOS
switch(letra)
{
case 'I': cout<<"\nEquivale a 1\n";
break;
case 'V': cout<<"\nEquivale a 5\n";
break;
case 'X': cout<<"\nEquivale a 10\n"; break;
case 'L': cout<<"\nEquivale a 50\n"; break;
case 'C': cout<<"\nEquivale a 100\n"; break;
case 'D': cout<<"\nEquivale a 500\n"; break;
case 'M': cout<<"\nEquivale a 1000\n"; break;
default: cout<<"\nNao euma letra do Sistema Romano\n";
}
cout<<"\n\n"; system("pause");
}
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;
int main()
{
float sal, salN, INSS, IR, salLiq;
char nome[31];int x;
RAV2 RAV3
ALGORITMOS
ALGORITMOS
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{ int i;
float deposito, soma = 0;
for (i = 1; i <= 10; i++)
{ cout << "\nDigite deposito: "; cin >> deposito;
soma += deposito;
}
cout<<"\nSoma: "<<soma<<endl;
system("pause");
}
RAV2 RAV3
ALGORITMOS
Observe o algoritmo
prog xxx
int C;
para(C<-1; C<=10; C++)
{
imprima "*";
}
imprima "\n\n";
fimprog
RAV2 RAV3
ALGORITMOS
Observe o algoritmo
prog xxx
int C;
para(C<-1; C<=10; C++)
{
imprima "*";
}
imprima "\n\n";
fimprog
RAV2 RAV3
ALGORITMOS
prog xxx
int C, L;
para(L<-1; L<=10; L++)
{
para(C<-1; C<=10; C++)
{ imprima "*"; }
imprima "\n";
}
imprima "\n\n";
fimprog
RAV2 RAV3
ALGORITMOS
prog xxx
int C, L;
para(L<-1; L<=10; L++)
{
para(C<-1; C<=10; C++)
{ imprima "*"; }
imprima "\n";
}
imprima "\n\n";
fimprog
RAV2 RAV3
ALGORITMOS
prog xxx
int C, L;
para(L<-1; L<=10; L++)
{
para(C<-1; C<= L ; C++)
{ imprima "*"; }
imprima "\n";
}
imprima "\n\n";
fimprog
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
int i, idade, conta = 0;
for (i = 1; i <= 50; i++)
{
cout << "\nDigite idade: "; cin >> idade;
if(idade >= 65) conta++;
}
cout<<"\nTotal: "<<conta<<endl;
system("pause");
}
RAV2 RAV3
ALGORITMOS
Uma
Um comando leia, ou de atribuio, antes do enquanto/
while para entrar na repetio e um comando leia, ou de
atribuio, antes de fechar o enquanto/ while, para repetir
ou sair da repetio.
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{ int c=0, n;
while(c < 20 )
{
cout<<"\nDois Numero maior que 0: "; cin>>n;
cout<<"\nRaiz: "<< sqrt(n)<<endl;
c+=2;
}
cout<<"\n\n"; system("pause");
}
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
#include <cmath>
simulada pelo while?
using namespace std;
int main()
{ int c=0, n;
while(c < 20 )
{
cout<<"\nDois Numero maior que 0: "; cin>>n;
cout<<"\nRaiz: "<< sqrt(n)<<endl;
c+=2;
}
cout<<"\n\n"; system("pause");
}
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
#include <cmath>
simulada pelo while?
using namespace std;
int main()
{ int c=0, n;
while(c < 20 )
{
cout<<"\nDois Numero maior que 0: "; cin>>n;
cout<<"\nRaiz: "<< sqrt(n)<<endl;
c+=2;
}
cout<<"\n\n"; system("pause");
}
for
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
#include <cmath>
simulada pelo while?
using namespace std;
int main()
Quantas vezes o bloco
{ int c=0, n;
ser repetido?
while(c < 20 )
{
cout<<"\nDois Numero maior que 0: "; cin>>n;
cout<<"\nRaiz: "<< sqrt(n)<<endl;
c+=2;
}
cout<<"\n\n"; system("pause");
}
for
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
#include <cmath>
simulada pelo while?
using namespace std;
int main()
Quantas vezes o bloco
{ int c=0, n;
ser repetido?
while(c < 20 )
{
cout<<"\nDois Numero maior que 0: "; cin>>n;
cout<<"\nRaiz: "<< sqrt(n)<<endl;
c+=2;
}
cout<<"\n\n"; system("pause");
}
for
10
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ float n1, n2, med;
cout<<"\nDois numeros >= 0: "; cin>>n1>>n2;
while(n1 >= 0 && n2 >= 0)
{
med=( n1 + n2 )/2;
cout<<"\nMedia: "<< med << "\n\n";
cout<<"\nDois numeros >= 0: "; cin>>n1>>n2;
}
cout<<"\n\n"; system("pause");
}
RAV2 RAV3
ALGORITMOS
Aprendemos a criar
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int c=3, soma=0;
do
{
soma += c;
c+=3;
}while(c <= 90 );
cout<<"\nSoma: "<<soma;
cout<<"\n\n"; system("pause");
}
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
using namespace std;
simulada pelo do while?
int main()
{
int c=3, soma=0;
do
{
soma += c;
c+=3;
}while(c <= 90 );
cout<<"\nSoma: "<<soma;
cout<<"\n\n"; system("pause");
}
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
using namespace std;
simulada pelo do while?
int main()
{
int c=3, soma=0;
do
{
soma += c;
c+=3;
}while(c <= 90 );
cout<<"\nSoma: "<<soma;
cout<<"\n\n"; system("pause");
}
for
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
using namespace std;
simulada pelo do while?
int main()
{
Quais os nmeros que
int c=3, soma=0;
sero somados?
do
{
soma += c;
c+=3;
}while(c <= 90 );
cout<<"\nSoma: "<<soma;
cout<<"\n\n"; system("pause");
}
for
RAV2 RAV3
ALGORITMOS
Observe o programa
#include <iostream>
#include <cstdlib>
Que estrutura est sendo
using namespace std;
simulada pelo do while?
int main()
{
Quais os nmeros que
int c=3, soma=0;
sero somados?
do
{
3:6:9:...:84:87:90,
soma += c;
totalizando, 30 nmeros
c+=3;
}while(c <= 90 );
cout<<"\nSoma: "<<soma;
cout<<"\n\n"; system("pause");
}
for
RAV2 RAV3
ALGORITMOS
MATRIZES
A1x4
13
Unidimensional(vetor)
bidimensional
Amxn
a11
a21
a31
...
...
2
A4x1
3
1
13
ALGORITMOS
int
float
double
char
long long int
...
RAV2 RAV3
ALGORITMOS
DECLARAO / ATRIBUIO
Numrico ou vetor de char unidimensional
RAV2 RAV3
ALGORITMOS
TRECHO de ENTRADA
Numrico ou char* de um caracter unidimensional
Uma palavra
Mais de uma
palavra
RAV2 RAV3
ALGORITMOS
TRECHO de SADA
Numrico ou char* (Matriz Coluna) unidimensional
RAV2 RAV3
ALGORITMOS
ALGORITMOS
ALGORITMOS
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
ALGORITMOS
MATRIZES BIDIMENSIONAIS
Notas4x4
Amxn
a11
a21
a31
...
...
9 7 8,5
5 7 8
10 4 6 7
6
5 9
5,5
ALGORITMOS
int
float
double
char
long long int
...
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
Matriz somaLinha
70
mat4x3
30 150
250
300 50 200
550
120 80 100
130 70 200
somaLinha
300
400
RAV2 RAV3
ALGORITMOS
RAV2 RAV3
ALGORITMOS
ALGORITMOS
Matriz somaColuna
70
30 150
300 50 200
mat4x3
120 80 100
130 70 200
RAV2 RAV3
ALGORITMOS
ALGORITMOS
M5x5
- - - -
- - - -
- - - -
- - - -
- - - -
RAV2 RAV3
ALGORITMOS
Dimensionamento
Entrada
RAV2 RAV3
ALGORITMOS
Dimensionamento
float M[5][5]; int L, C;
Entrada
RAV2 RAV3
ALGORITMOS
Dimensionamento
float M[5][5]; int L, C;
Entrada
for(L=0; L < 5 ; L++)
{
for(C=0; C < 5 ;C++)
{
cout<<"\nElemento "<<L+1<<", "<<C+1<<": ";
cin>>M[L][C];
}
}
RAV2 RAV3
ALGORITMOS
Saida
RAV2 RAV3
ALGORITMOS
Saida
system("cls");
cout<<"\nElementos da Matriz\n\n";
for (L= 0; L < 5 ; L++)
{
for(C=0; C < 5 ; C++)
cout<<M[L][C]<< "\t";
cout<<"\n\n";
}
RAV2 RAV3
ALGORITMOS
system("cls");
cout<<"\nElementos da Matriz Acima da DP\n\n";
for (L= 0; L < TAM ; L++)
{
for(C=0; C < TAM ; C++)
if( L < C )
cout<<M[L][C]<< "\t";
else
cout<<"\t";
cout<<"\n";
}
RAV2 RAV3
ALGORITMOS
system("cls");
cout<<"\nElementos da Matriz Acima da DP\n\n";
for (L= 0; L < TAM ; L++)
{
for(C=0; C < TAM ; C++)
if( L < C )
cout<<M[L][C]<< "\t";
else
cout<<"\t";
cout<<"\n";
}
RAV2 RAV3
ALGORITMOS
if( L > C )
cout<<M[L][C]<< "\t"; //Triangulo Superior DP
else
cout<<"\t";
if( L == C )
cout<<M[L][C]<< "\t"; //Diagonal Principal
else
cout<<"\t";
RAV2 RAV3
ALGORITMOS
Biblioteca cstring
strlen(str)
strcpy(strD, strO)
strcmp(str1, str2)
strcat(str1, str2)
strupr(str) **
strlwr(str) **
ALGORITMOS
Biblioteca cctype
isdigit(char c)
RAV2 RAV3
ALGORITMOS
Biblioteca cstdlib
atoi(str[])
atoII(str[])
atof(str[])
RAV2 RAV3
ALGORITMOS
Biblioteca iomanip
setw(int n)
setfill(char c)
fixed
left
right
oct
hex
uppercase
ALGORITMOS
Resumindo
RAV2 RAV3