Escolar Documentos
Profissional Documentos
Cultura Documentos
/*----------------*/
void barra( float x )
{
float final, passo;
int i;
final = 50.0 * ( x + 0.01 - min ) / ( max + 0.01 - min );
passo = 0.0; /* Imprime de 1 a 50 dependendo do x recebido. */
i
= 0;
while( passo++ < final )
if( ++i % 10 )
putch( '=' );
else
putch( '*' ); /* Imprime um '*' a cada 10 impressoes feitas. */
}
/*----------------*/
void extremos( float array[] ) /* Note que passamos um array como parametro. */
{
int i;
max = min = array[0];
for( i = 1; i < 10; i++ ) /* Computa maximo e minimo. */
{
if( min > array[i] )
min = array[i];
if( max < array[i] )
max = array[i];
}
}
*/
*/
*/
*/
int indice;
long quantidade;
long valor, centavos;
printf( "\nCalcula quantas notas precisa para um valor em dinheiro.\n\n" );
printf( "Entre com um valor em dinheiro (R$###,##): R$" );
scanf( "%ld,%ld", &valor, ¢avos );
indice = 0;
while( valor > 0 )
{
quantidade = valor / valores[indice];
if( quantidade )
*/
*/
#define LINHAS 5
#define COLUNAS 10
/* Jogo de batalha naval. --------------------------------------------*/
int main() /* Exemplo de uso de matrizes 2. Matriz de duas dimensoes. */
{
char inimigo[LINHAS][COLUNAS] =
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 1, 1, 0, 0, 1, 0, 1},
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
{ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{ 1, 0, 1, 1, 1, 0, 0, 0, 0, 0} };
char tentativas[LINHAS][COLUNAS];
int i, j;
int alvos;
int acertos;
/* Inicia as tentativas e conta os alvos a acertar. ----------------*/
alvos = 0;
for( i = 0; i < LINHAS; i++ )
for( j = 0; j < COLUNAS; j++ )
{
tentativas[i][j] = '.';
if( inimigo[i][j] )
alvos++;
}
acertos = 0;
while( acertos < alvos )
{
for( i = 0; i < LINHAS; i++ ) /* Imprime a posicao atual. */
{
for( j = 0; j < COLUNAS; j++ )
printf( "%c ", tentativas[i][j] );
printf( "\n\n" );
}
printf( "Coordenadas de tiro( x, y ):" );
scanf( "%d, %d", &i, &j );
if( inimigo[i][j] )
{
tentativas[i][j] = '\xDB'; /* Acertou. */
acertos++;
}
else
tentativas[i][j] = '\xB1'; /* Errou. */
}
system( "PAUSE" );
return 0;
}
*/
*/
*/
*/
*/
*/
*/
*/
<conio.h>
<string.h>
<stdio.h>
<stdlib.h>
/*
/*
/*
/*
*/
*/
*/
*/
#define NUM_USERS 5
int main() /* Exemplo de uso de strings. Manipulacao. ----------------*/
{
static char nome[NUM_USERS][21] = /* Nomes de no maximo 20 caracteres. */
{ "Goya",
"Ulisses",
"Angelo",
"Julio",
"Ricardo" }; /* Tabela de usuarios. */
static char senhas[NUM_USERS][6] = /* Senha de no maximo 5 caracteres. */
{ "12345",
"a",
"aaaaa",
"abcd",
"x"
}; /* Tabela de senhas.
*/
char User[21]; /* Nome teclado pelo usuario. */
char senha[6]; /* Senha teclada pelo usuario. */
char ch;
int i, j;
int achou = 0;
printf( "\nUsercode: " ); /* Le o nome de usuario. */
gets( User );
for( i = 0; i < NUM_USERS; i++ )
/* Procura na tabela de usuario. */
if( stricmp( nome[i], User ) == 0 ) /* Compara ignorando case. Achou ? */
{
achou = 1;
break;
}
if( achou )
{
printf( "\nSenha: " );
j = 0;
while( ((ch = getch()) != '\r') && (j < 5) ) /* Le a senha. */
{
senha[j] = ch; /* Le sem ecoar e imprime '*'. */
putch( '*' );
j++;
}
senha[j] = '\0'; /* Termina o string colocando \0 no final. */
if( strcmp( senhas[i], senha ) == 0 ) /* A senha eh correta ? */
printf( "\nOla sr. %s !\nComo vai ?\n", User );
else
printf( "\n\aSenha \ainvalida!\n\aPrendam \aeste \acara !\n" );
}
else
printf( "Usuario nao cadastrado." );
system( "PAUSE" );
return 0;
}
<time.h>
<string.h>
<stdio.h>
<stdlib.h>
/*
/*
/*
/*
*/
*/
*/
*/
{
printf( "\nDigite a seguinte frase:\n%s\n", teste );
time( &inicio ); /* time devolve o numero de segundos deste
meia noite.
gets( resposta );
*/
time( &final );
if( strcmp( teste, resposta ) != 0 ) /* Compara os strings. */
printf( "\nVoce errou a digitacao. Tente de novo." );
else
break; /* Sai do while. */
}
printf( "\nParabens. Voce passou no teste." );
tempo = difftime( final, inicio ); /* difftime calcula a diferenca
entre final e inicial.
*/
printf( "\nSeu tempo foi de %.1f segundos.\n\n", tempo );
system( "PAUSE" );
return 0;
}
*/
*/
*/
*/
*/
*/
<ctype.h>
<string.h>
<stdio.h>
<stdlib.h>
/*
/*
/*
/*
*/
*/
*/
*/
int main()
{
int ch;
do
{
printf( "\n\nPressione uma tecla( Enter para terminar ): " );
ch = getche();
if( isalpha( ch ) )
printf( "\nE\' um caracter alfanumerico." );
if( isupper( ch ) )
printf( "\nE\' maiusculo." );
if( islower( ch ) )
printf( "\nE\' minusculo." );
if( isdigit( ch ) )
printf( "\nE\' um digito numerico." );
if( isxdigit( ch ) )
printf( "\nE\' um digito hexadecimal." );
if( isspace( ch ) )
printf( "\nE\' um separador." );
if( isalnum( ch ) )
printf( "\nE\' um caracter alfanumerico." );
if( ispunct( ch ) )
printf( "\nE\' um caracter de pontuacao." );
if( isprint( ch ) )
printf( "\nE\' um possivel de ser impresso." );
if( isgraph( ch ) )
printf( "\nE\' um caracter grafico." );
if( iscntrl( ch ) )
printf( "\nE\' um Ctrl." );
if( isascii( ch ) )
printf( "\nE\' um caracter ASCII." );
}
while( ch != '\r' );
system( "PAUSE" );
return 0;
}
#include <stdio.h>
#include <stdlib.h>
main()
{
char
int
long
float
string[81];
i, j;
l;
f;
*/
*/