Powered By Blogger

sábado, 31 de janeiro de 2015

Calculadora Simples em C

Código escrito por Naylson P. Carvalho:

#include <stdio.h>

int soma(int a, int b){
return a + b;
}

int subitracao(int a, int b){
return a - b;
}

int multiplicacao(int a, int b){
return a * b;
}

int divisao(int a, int b){
return a / b;
}

int main() {

int x, menu, a, b;

printf("|||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("|||||||||| Digite 1 para Adicao        ||||||||||\n");
printf("|||||||||| Digite 2 para Subitracao    ||||||||||\n");
printf("|||||||||| Digite 3 para Multiplicacao ||||||||||\n");
printf("|||||||||| Digite 4 para Divisao       ||||||||||\n");
printf("|||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
scanf("%d", &menu);

printf("Informe um numero: \n");
scanf("%d", &a);
printf("Informe outro numero: \n");
scanf("%d", &b);

if(menu == 1){
x = soma(a, b);
printf("RESULTADO >> %d\n", x);
} else if(menu == 2){
x = subitracao(a, b);
printf("RESULTADO >> %d\n", x);
} else if(menu == 3){
x = multiplicacao(a, b);
printf("RESULTADO >> %d\n", x);
} else if(menu == 4){
x = divisao(a, b);
printf("RESULTADO >> %d\n", x);
} else {
printf("Operação Invalida !\n");
}

return 0;
}

Matriz contabilizadora de dados - Contando Letras, Números, acentos e espaços.

Código Escrito por Naylson P. Carvalho:

#include <stdio.h>

int main(){
int a, b, c, d, e, f, a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0, f1 = 0;
int g, h, i, j, k, l, m, tc, tl, g1 = 0, h1 = 0, i1 = 0, j1 = 0, k1 = 0, l1 = 0, m1 = 0;
int matrix1[34] = {3, 49, 0, 1, 429, 19, 9, 9, 0, 2, 12, 5, 238, 6, 72, 999, 1, 2, 9, 23, 59, 17, 2, 4, 6, 6, 0, 102, 22, 45, 50, 2, 1, 72};
char matrix2[105] = {"Toma La da Cá Amisterdã da lân For de For ALIEN versus P Caroção Impulsione laço pão de ló e é incrivelb"};

for(a = 0; a < 34; a++){ 
if(matrix1[a] == 0){
a1++;
}
}
for(b = 0; b < 34; b++){ 
if(matrix1[b] % 2 == 0){
b1++;
}
}
for(c = 0; c < 34; c++){ 
if(matrix1[c] % 2 == 1){
c1++;
}
}
for(d = 0; d < 34; d++){ 
if(matrix1[d] % 3 == 0){
d1++;
}
}
for(e = 0; e < 34; e++){ 
if(matrix1[e] % 5 == 0){
e1++;
}
}
for(f = 0; f < 34; f++){ 
if(matrix1[f] % 2 == 1 || matrix1[f] % 2 == 0){
f1++;
}
}
for(g = 0; g < 105; g++){ 
if(matrix2[g] == 'a' || matrix2[g] == 'e' || matrix2[g] == 'i' || matrix2[g] == 'o' || matrix2[g] == 'u'
|| matrix2[g] == 'A' || matrix2[g] == 'E' || matrix2[g] == 'I' || matrix2[g] == 'O' || matrix2[g] == 'U'){
g1++;
}
}
for(h = 0; h < 105; h++){ 
if(matrix2[h] == 'b' || matrix2[h] == 'B' || matrix2[h] == 'c' || matrix2[h] == 'C' || matrix2[h] == 'd'
|| matrix2[h] == 'D' || matrix2[h] == 'f' || matrix2[h] == 'F' || matrix2[h] == 'g' || matrix2[h] == 'G'
|| matrix2[h] == 'h' || matrix2[h] == 'H' || matrix2[h] == 'j' || matrix2[h] == 'J' || matrix2[h] == 'k'
|| matrix2[h] == 'K' || matrix2[h] == 'l' || matrix2[h] == 'L' || matrix2[h] == 'm' || matrix2[h] == 'M'
|| matrix2[h] == 'n' || matrix2[h] == 'N' || matrix2[h] == 'p' || matrix2[h] == 'P' || matrix2[h] == 'q'
|| matrix2[h] == 'Q' || matrix2[h] == 'r' || matrix2[h] == 'R' || matrix2[h] == 's' || matrix2[h] == 'S'
|| matrix2[h] == 't' || matrix2[h] == 'T' || matrix2[h] == 'v' || matrix2[h] == 'V' || matrix2[h] == 'w'
|| matrix2[h] == 'W' || matrix2[h] == 'x' || matrix2[h] == 'X' || matrix2[h] == 'y' || matrix2[h] == 'Y'
|| matrix2[h] == 'z' || matrix2[h] == 'Z'){
h1++;
}
}
for(i = 0; i < 105; i++){ 
if(matrix2[i]== 'A' || matrix2[i] == 'E' || matrix2[i] == 'I' || matrix2[i] == 'O' || matrix2[i] == 'U'){
i1++;
}
}
for(j = 0; j < 105; j++){ 
if(matrix2[j] == 'a' || matrix2[j] == 'e' || matrix2[j] == 'i' || matrix2[j] == 'o' || matrix2[j] == 'u'){
j1++;
}
}
for(k = 0; k < 105; k++){ 
if(matrix2[k] == 'á' || matrix2[k] == 'é' || matrix2[k] == 'í' || matrix2[k] == 'ó' || matrix2[k] == 'ú'
|| matrix2[k] == 'â' || matrix2[k] == 'ê' || matrix2[k] == 'î' || matrix2[k] == 'ô' || matrix2[k] == 'û'
|| matrix2[k] == 'ã' || matrix2[k] == 'õ'){
k1++;
}
}
for(l = 0; l < 105; l++){ 
if(matrix2[l] == 'ç'){
l1++;
}
}
for(m = 0; m < 105; m++){ 
if(matrix2[m] == ' '){
m1++;
}
}
tl = (g1 + h1);
tc = (tl + f1);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("|||||||||||||||||| Resultado Final |||||||||||||||||\n");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("|||||||||||||||||||||| Numeros |||||||||||||||||||||\n");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("|||||||| Quantidade de Zeros          >>> %i  |||||||\n", a1);
printf("|||||||| Quantidade de Pares          >>> %i |||||||\n", b1);
printf("|||||||| Quantidade de Impares        >>> %i |||||||\n", c1);
printf("|||||||| Quantidade de Multiplos de 3 >>> %i |||||||\n", d1);
printf("|||||||| Quantidade de Multiplos de 5 >>> %i  |||||||\n", e1);
printf("|||||||| Quantidade Total de Nuemros  >>> %i |||||||\n", f1);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("|||||||||||||||||||||| Letras ||||||||||||||||||||||\n");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("|||||||| Quantidades de Vogais        >>> %i |||||||\n", g1);
printf("|||||||| Quantidades de Consoantes    >>> %i |||||||\n", h1);
printf("|||||||| Quantidades de Vogais Maius. >>> %i  |||||||\n", i1);
printf("|||||||| Quantidades de Vogais Minus. >>> %i |||||||\n", j1);
printf("|||||||| Quantidades de Acentos       >>> %i  |||||||\n", k1);
printf("|||||||| Quantidades de Cedilhas      >>> %i  |||||||\n", l1);
printf("|||||||| Quantidades de Espacos       >>> %i |||||||\n", m1);
printf("|||||||| Quantidade Total de Letras   >>> %i |||||||\n", tl);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
printf("||||||||||||| Total de Caracteres = %i ||||||||||||\n", tc);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||\n\n");
return 0;
}

segunda-feira, 26 de janeiro de 2015

Matriz - contando vogais consoantes e espaços


Código desenvolvido pelo programador Samuel Lima:

#include<stdio.h>
#include<conio.h>
void Janela5(){system("Color F0");
int lin, col;
for ( lin = 0; lin <= 25; lin++ ){
for ( col = 0; col <= 80; col++ ){
gotoxy( col, lin );
if ( lin == 2 ){textbackground(LIGHTBLUE);printf( " ");}
if ( col == 1 ){textbackground(LIGHTBLUE);printf(" ");}
if ( lin == 25 ){textbackground(LIGHTBLUE);}
if ( col == 80 ){textbackground(LIGHTBLUE);printf(" ");}
}
}textbackground( BLACK );
}
void inicio( ){system ("title MATRIZ : CONTANDO VOGAIS CONSOANTES E ESPAÇOS");
int i;do{Janela5();textbackground(WHITE);
textcolor(LIGHTRED);gotoxy(21,7);printf("MATRIZ : CONTANDO VOGAIS CONSOANTES E ESPAÇOS");
textcolor(BROWN);gotoxy(25,10);printf("Programa desenvolvido por:");
textcolor(BLACK);gotoxy(52,10);printf("Samuel Lima");
textcolor(BLUE);gotoxy(34,12);printf("sa_sp10@hotmail.com");
textcolor(LIGHTBLUE);gotoxy(24,14);printf("DIGITE    PARA SAIR OU   PARA CONTINUAR  ");
textcolor(LIGHTRED);gotoxy(32,14);printf("1");textcolor(LIGHTRED);gotoxy(47,14);printf("2");
gotoxy(41,16);
scanf("%d",&i);fflush(stdin);
if( i == 1 ){textcolor(LIGHTRED);gotoxy(35,20);printf ("MUITO OBRIGADO");Sleep(1800);exit(0);}
if( i == 2 ){system("cls"); return;}
else {textcolor(LIGHTRED);gotoxy(37,20);printf ("\aOPÇÃO ERRADA");Sleep(1800);system("cls");}
}
while ( i );
}
int main(){
inicio();textbackground(WHITE);
char ch = 0;
int totvogmi = 0, totvogma = 0, totacet = 0,
totced = 0, totcon = 0, totcar = 0;
int j, w, x, y = 0, et = 0, ced = 0, ced01 = 0,
a = 0, e = 0, i = 0, o = 0, u = 0,
A = 0, E = 0, I = 0, O = 0, U = 0,
a0 = 0, a01 = 0, a02 = 0, a03 = 0,
e01 = 0, e02 = 0, i01 = 0,
o01 = 0, o02 = 0, o03 = 0,
u01 = 0, u02 = 0,
A0 = 0, A01 = 0, A02 = 0, A03 = 0,
E01 = 0, E02 = 0, I01 = 0,
O01 = 0, O02 = 0, O03 = 0,
U01 = 0, U02 = 0;
char Vet [ 16 ];
char matriz [ 11 ] [ 16 ] =
       {{"João Eugênio"    },
{"Átila Antônio"   },
{"Irene Patrícia"  },
{"Mônica Simões"   },
{"Ester Büeno"     },
{"Graça Núbia"     },
{"Fábio Júnior"    },
{"Ozéias Gonçalo"  },
{"Lúcia Píres"     },
{"Ulisses Ângelo"  },
{"Ítalo Guimarães" }};
system("cls");Janela5();textbackground(WHITE);
textcolor(LIGHTRED);gotoxy(20,3);printf("MATRIZ : CONTANDO VOGAIS CONSOANTES E ESPAÇOS");
textcolor(LIGHTRED);gotoxy(9,5);printf( "Nomes da Matriz" );
textcolor(LIGHTRED);gotoxy(36,5);printf( "Cada linha" );
textcolor(LIGHTRED);gotoxy(52,5);printf( "Conteúdo da Matriz" );
for (w = 0; w < 11; w++) {
gotoxy(5, w + 7);textcolor(BLACK);
for ( j = 0; j < 16; j++ ) {
printf(" %c", matriz [ w ] [ j ] );
Vet [ y ] =  matriz [ w ] [ j ];
y++;
}x = 11 * 16;
textcolor(LIGHTRED);printf("%d ", strlen ( matriz [ w ] ) );
textcolor(LIGHTBLUE);printf("letras");
totcar += strlen ( matriz [ w ] );
}
for ( y = 0; y < x; y++ ) {
ch = Vet [ y ];
if ( ch == 'a' )a++; if ( ch == 'e' )e++;   if ( ch == 'i' )i++;
if ( ch == 'o' )o++; if ( ch == 'u' )u++;   if ( ch == 'A' )A++;
if ( ch == 'E' )E++; if ( ch == 'I' )I++;   if ( ch == 'O' )O++;
if ( ch == 'U' )U++;
if ( ch == 'à' )a0++; if ( ch == 'á' )a01++;if ( ch == 'ã' )a02++;
if ( ch == 'â' )a03++;
if ( ch == 'é' )e01++;if ( ch == 'ê' )e02++;
if ( ch == 'í' )i01++;if ( ch == 'ó' )o01++;if ( ch == 'õ' )o02++;
if ( ch == 'ô' )o03++;if ( ch == 'ú' )u01++;if ( ch == 'ü' )u02++;
if ( ch == 'À' )A0++; if ( ch == 'Ã' )A01++;if ( ch == 'Á' )A02++;
if ( ch == 'Á' )A03++;
if ( ch == 'É' )E01++;if ( ch == 'Ê' )E02++;if ( ch == 'Í' )I01++;
if ( ch == 'Ó' )O01++;if ( ch == 'Õ' )O02++;if ( ch == 'Ô' )O03++;
if ( ch == 'Ú' )U01++;if ( ch == 'Ü' )U02++;
if ( ch == 'ç' )ced++;if ( ch == 'Ç' )ced01++;
if ( ch == ' ' )et++;
}
totvogmi = ( a + e + i + o + u );
totvogma = ( A + E + I + O + U );
totacet = ( a0 + a01 + a02 + a03 + e01 + e02 + i01 + o01 + o02 + o03 + u01 + u02 +
A0 + A01 + A02 + A03 + E01 + E02 + I01 + O01 + O02 + O03 + U01 + U02 );
totced = ( ced + ced01 );
totcon = totcar - ( totvogmi + totvogma + totacet + totced );
textcolor(BLACK);gotoxy(50,7);printf("vogais a minúsculo = ");
textcolor(LIGHTRED);printf("%d", a );
textcolor(BLACK);gotoxy(50,8);printf("vogais e minúsculo = ");
textcolor(LIGHTRED);printf("%d", e );
textcolor(BLACK);gotoxy(50,9);printf("vogais i minúsculo = ");
textcolor(LIGHTRED);printf("%d", i );
textcolor(BLACK);gotoxy(50,10);printf("vogais o minúsculo = ");
textcolor(LIGHTRED);printf("%d", o );
textcolor(BLACK);gotoxy(50,11);printf("vogais u minúsculo = ");
textcolor(LIGHTRED);printf("%d", u );
textcolor(BLACK);gotoxy(50,12);printf("vogais A maiúsculo = ");
textcolor(LIGHTRED);printf("%d", A );
textcolor(BLACK);gotoxy(50,13);printf("vogais E maiúsculo = ");
textcolor(LIGHTRED);printf("%d", E );
textcolor(BLACK);gotoxy(50,14);printf("vogais I maiúsculo = ");
textcolor(LIGHTRED);printf("%d", I );
textcolor(BLACK);gotoxy(50,15);printf("vogais O maiúsculo = ");
textcolor(LIGHTRED);printf("%d", O );
textcolor(BLACK);gotoxy(50,16);printf("vogais U maiúsculo = ");
textcolor(LIGHTRED);printf("%d", U );
textcolor(BLACK);gotoxy(50,17);printf("total de espaços   = ");
textcolor(LIGHTRED);printf("%d", et );
textcolor(BLACK);gotoxy(50,18);printf("Cedilhas minúscula = ");
textcolor(LIGHTRED);printf("%d", ced );
textcolor(BLACK);gotoxy(50,19);printf("Cedilhas maiúscula = ");
textcolor(LIGHTRED);printf("%d", ced01 );
textcolor(BLACK);gotoxy(5,19);printf("Todas consoantes   = ");
textcolor(LIGHTRED);printf("%d", totcon );
textcolor(BLACK);gotoxy(5,20);printf("vogais minúscula   = ");
textcolor(LIGHTRED);printf("%d", totvogmi );
textcolor(BLACK);gotoxy(5,21);printf("vogais maiúscula   = ");
textcolor(LIGHTRED);printf("%d", totvogma );
textcolor(BLACK);gotoxy(5,22);printf("Todos acentuados   = ");
textcolor(LIGHTRED);printf("%d", totacet );
textcolor(BLACK);gotoxy(5,23);printf("Todos as cedilhas  = ");
textcolor(LIGHTRED);printf("%d", totced );
textcolor(BLACK);gotoxy(50,21);printf("Todos Caracteres = ");
textcolor(LIGHTRED);printf("%d", totcar );
Sleep(1800);textcolor(LIGHTRED);gotoxy(50,23);
printf("MUITO OBRIGADO");
getche();
return(0);
}