sexta-feira, 30 de novembro de 2012

Preenchendo um Vetor e operando

Preenchendo um Vetor e operando, este programa é muito semelhante a um outro
já postado, na verdade no outro o Vetor [8] [2] é declarado e inicializado,
neste ele é preenchido e as operações são as mesmas, muito bom código,
teste e confira o ótimo funcionamento deste programa.

Criado no eclipse que é excelente IDE também para C/C++

#include <stdio.h>
#include <conio2.h>
int Vetor [8] [2];
//int Vetor [8] [2] = {{10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}};
int par [8]; int impar [8]; int i, j, f, resp;
int main(){
    system ("title PREENCHENDO UM VETOR E OPERANDO");
    textbackground(BLACK);
    textcolor(LIGHTRED);gotoxy(30,3);printf ( "PREENCHENDO UM VETOR E OPERANDO" );
    textcolor(YELLOW);gotoxy(35,5);printf("sa_sp10@hotmail.com");
    for(f = 0; f < 9; f++){
        textcolor(LIGHTGREEN);gotoxy(25,7);printf("Digite um Numero para a posicao");
        textcolor(LIGHTRED);gotoxy(57,7);printf("%d:  ", f);
        textcolor(YELLOW);scanf("%d",& Vetor [f] [0]);fflush(stdin);
    }
    int  f = 0;
    int  m = Vetor [f] [0];
    int g = Vetor [f] [0];
    for ( f = 0; f < 8; f++ ){
        if ( Vetor [f] [0] > m ){
            m = Vetor [f] [0];
        }
        if ( Vetor [f] [0] < g ){
            g = Vetor [f] [0];
        }
    }
    textbackground(BLACK);
    textcolor(LIGHTBLUE);gotoxy(8,9);printf("Estes são os elementos do Vetor: ");
    gotoxy(8,11);Sleep(800);
    for(f = 0; f < 8; f++){
        textcolor(LIGHTMAGENTA);printf(" %d ", Vetor[f] [0]);
    }
    textcolor(LIGHTBLUE);gotoxy(8,13);printf ( "Esta e a soma dos indices do Vetor: " );
    gotoxy(43,13);textcolor(LIGHTMAGENTA);Sleep(800);
    for ( f = 0; f < 8; f++ ){
        resp += Vetor [f] [0];
    }
    printf ( "  %d ",  resp);
    Sleep(800);
    textcolor(LIGHTBLUE);gotoxy(8,15);printf("O maior Numero no Vetor e:");
    textcolor(LIGHTMAGENTA);gotoxy(36,15);printf(" %d ", m);
    textcolor(LIGHTBLUE);gotoxy(8,17);printf("O menor Numero no Vetor e:");
    textcolor(LIGHTMAGENTA);gotoxy(36,17);printf("%d", g);
    Sleep(800);
    for (f = 0; f < 8; f++){
        if (Vetor [f] [0] % 2 == 0) par [i++] = Vetor [f] [0];
        else
            impar [j++] = Vetor [f] [0];
    }
    textcolor(LIGHTBLUE);gotoxy(8,19);printf("Numeros pares no vetor: ");
    for(f = 0; f < i; f++){
        textcolor(LIGHTMAGENTA);printf(" %d ", par [f]);
    }
    Sleep(800);
    textcolor(LIGHTBLUE);gotoxy(8,21);printf("Numeros Impares no vetor: ");
    for(f = 0; f < i; f++){
        textcolor(LIGHTMAGENTA);printf(" %d ", impar [f]);
    }
    Sleep(800);
    textcolor(LIGHTRED);gotoxy(33,23);printf ( "O ROCCO AGRADECE" );
    getche();
}

Nenhum comentário:

Postar um comentário

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