sexta-feira, 30 de novembro de 2012

As quatros operações Matemáticas em Vetor pré - definido

AS 4 OPERAÇÕES MATEMÁTICAS EM VETOR PRÉ - DEFINIDO, vem Mostrando aos iniciantes em Linguagem C,
e que estão estudando Vetores, como fazerem estas operações de uma forma bem prática.
Declarei e inicializei o vetor A [], de cinco posições onde estão inseridos os elementos que farão parte das operações.
Evidentemente também declarei o Vetor B[5], onde serão armazenados os resultados do Vetor A [], e comentei as linhas do 32 ao 39.
Nem precisa falar sobre os laços for usados, pois está muito claro o uso e todos sabem da necessidade.
O programa foi criado no eclipse, e não mostrou nenhum warnigs ao contrário do outro programa
postado nesta mesma página e que é muito semelhante a este.

Enfim, tá aí, más um ótimo código didático em linguagem C.

copie, cole e compile:

#include <stdio.h>
#include <conio2.h>
void Janela(){
    int i = 0;
    textcolor(12); //inicio do menu
    for(i = 2; i < 25; i++) {
        gotoxy(1, i); //linha da direita
        printf("\xdb\xdb");
    }
    for(i = 2; i < 25; i++) {
        gotoxy(80, i); //linha da esquerda
        gotoxy(79, i);
        printf("\xdb\xdb");
    }
    gotoxy(1,2);
    int index = 0, contador;
    char letras [5] = "\xdb";
    for (contador = 0; contador < 80; contador++)
    {
        printf("%c",letras [index]);
    }
    gotoxy(1,25);
    for (contador = 0; contador < 80; contador++)
    {
        printf("%c", letras [index]);
    }
}
int main(){
    system ("title AS 4 OPERACOES EM VETOR PRE - DEFINIDO");
    int A [] = {10, 20, 30, 40, 50}; int B [5], i;
    /*
   int A [5], B [5], i;Janela();
    textcolor(LIGHTRED);gotoxy(25,5);printf("AS 4 OPERACOES EM VETOR PRE - DEFINIDO");

    textcolor(LIGHTBLUE);gotoxy(27,7);printf("DIGITE 5 NUMEROS PARA O VETOR");
   for(i = 1; i <= 5; i++){
        textcolor(LIGHTGREEN);gotoxy(25,9);printf("Digite um Numero para a posicao");
        textcolor(LIGHTRED);gotoxy(57,9);printf("%d:  ", i);
        textcolor(YELLOW);scanf("%d",& A [i]);fflush(stdin);
    }
     */

    for(i = 0; i < 5; i++){
        B [i] = A [i] * 5;
    }
    system("cls");Janela();
    textcolor(LIGHTRED);gotoxy(22,5);printf("AS 4 OPERACOES EM VETOR PRE - DEFINIDO");
    textcolor(LIGHTBLUE);gotoxy(30,7);printf("VETOR MULTIPLICADO POR 5");
    textcolor(LIGHTGREEN);gotoxy(16,9);printf("VETOR A");
    textcolor(LIGHTGREEN);gotoxy(47,9);printf("VETOR B");
    for(i = 0; i < 5; i++){
        textcolor(YELLOW);gotoxy(14, 11 + i);printf("A [%d] = %d", i, A [i]);
        textcolor(LIGHTCYAN);gotoxy(46, 11 + i);printf("B [%d] = %d", i, B [i]);
    }
    getche();
    system("cls");Janela();
    textcolor(LIGHTRED);gotoxy(22,5);printf("AS 4 OPERACOES EM VETOR PRE - DEFINIDO");
    textcolor(LIGHTBLUE);gotoxy(30,7);printf("VETOR SOMADO COM 5");
    textcolor(LIGHTGREEN);gotoxy(16,9);printf("VETOR A");
    textcolor(LIGHTGREEN);gotoxy(47,9);printf("VETOR B");
    for(i = 0; i < 5; i++){
        B [i] = A [i] + 5;
    }
    for(i = 0; i < 5; i++){
        textcolor(YELLOW);gotoxy(14, 11 + i);printf("A [%d] = %d", i, A [i]);
        textcolor(LIGHTCYAN);gotoxy(46, 11 + i);printf("B [%d] = %d", i, B [i]);
    }
    getche();
    system("cls");Janela();
    textcolor(LIGHTRED);gotoxy(22,5);printf("AS 4 OPERACOES EM VETOR PRE - DEFINIDO");
    textcolor(LIGHTBLUE);gotoxy(30,7);printf("VETOR SUBTRAIDO 5");
    textcolor(LIGHTGREEN);gotoxy(16,9);printf("VETOR A");
    textcolor(LIGHTGREEN);gotoxy(47,9);printf("VETOR B");
    for(i = 0; i < 5; i++){
        B [i] = A [i] - 5;
    }
    for(i = 0; i < 5; i++){
        textcolor(YELLOW);gotoxy(14, 11 + i);printf("A [%d] = %d", i, A [i]);
        textcolor(LIGHTCYAN);gotoxy(46, 11 + i);printf("B [%d] = %d", i, B [i]);
    }
    getche();
    system("cls");Janela();
    textcolor(LIGHTRED);gotoxy(22,5);printf("AS 4 OPERACOES EM VETOR PRE - DEFINIDO");
    textcolor(LIGHTBLUE);gotoxy(30,7);printf("VETOR DIVIDIDO POR 5");
    textcolor(LIGHTGREEN);gotoxy(16,9);printf("VETOR A");
    textcolor(LIGHTGREEN);gotoxy(47,9);printf("VETOR B");
    for(i = 0; i < 5; i++){
        B [i] = A [i] / 5;
    }
    for(i = 0; i < 5; i++){
        textcolor(YELLOW);gotoxy(14, 11 + i);printf("A [%d] = %d", i, A [i]);
        textcolor(LIGHTCYAN);gotoxy(46, 11 + i);printf("B [%d] = %d", i, B [i]);
    }
    textcolor(LIGHTRED);gotoxy(33,21);printf ( "O ROCCO AGRADECE" );
    getche();
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.