domingo, 1 de dezembro de 2013

Programa União de Vetores

Este Programa está ápto à receber números inteiros para dois vetores, imprimindo
depois os vetores separadamente, e em seguida a união dos dois vetores em um terceiro vetor.O programa ainda ordena os elementos do terceiro vetor e mostra também o número
de ocorrência de cada um destes elementos.
Programa cem por cento funcional como todos os outros que postei, criado no eclipse,
compilado como sempre no MinGw, e rodando sem nenhum warnings.

Veja abaixo algumas imagens do programa em execção:




 Veja abaixo o código do Programa:

 #include<stdio.h>
#include <conio.h>
#define tam 5
void Janela5(){
    int lin, col;
    col = 0;
    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);
}
int V = 10;
int i, j, t, vezes, aux, ord;
int main(){
    system ("title PROGRAMA UNIAO DE VETORES");
    int Vetor [ tam ], Vet_or[ tam ], Vet [ V ];
    for ( i = 0; i < tam; i++ ) {Janela5();
    textcolor(LIGHTRED);gotoxy(29,3);printf("PROGRAMA UNIAO DE VETORES");
    textcolor(AMARELO);gotoxy(24,5);printf("Programa desenvolvido por:");
    textcolor(CIANOCLARO);gotoxy(51,5);printf("Samuel Lima");
    textcolor(VERDECLARO);gotoxy(34,7);printf("sa_sp10@hotmail.com");
    textcolor(LIGHTBLUE);gotoxy(19,9);printf("Digite um numero para a posicao " );
    textcolor(LIGHTRED);printf(" %d%c ", i + 0, 167 );
    textcolor(LIGHTBLUE);printf("do Vetor A" );
    textcolor(YELLOW);gotoxy(66, 9);scanf("%d", &Vetor [ i ] );fflush(stdin);system("cls");
    }system("cls");
    for ( i = 0; i < tam; i++ ) {Janela5();
    textcolor(LIGHTRED);gotoxy(29,3);printf("PROGRAMA UNIAO DE VETORES");
    textcolor(AMARELO);gotoxy(24,5);printf("Programa desenvolvido por:");
    textcolor(CIANOCLARO);gotoxy(51,5);printf("Samuel Lima");
    textcolor(VERDECLARO);gotoxy(34,7);printf("sa_sp10@hotmail.com");
    textcolor(LIGHTBLUE);gotoxy(19,9);printf("Digite um numero para a posicao " );
    textcolor(LIGHTRED);printf(" %d%c ", i + 0, 167 );
    textcolor(LIGHTBLUE);printf("do Vetor B" );
    textcolor(YELLOW);gotoxy(66, 9);scanf("%d", &Vet_or [ i ] );fflush(stdin);system("cls");
    }Janela5();
    textcolor(LIGHTRED);gotoxy(29,3);printf("PROGRAMA UNIAO DE VETORES");
    textcolor(YELLOW);gotoxy(25,5);printf("ESTES SAO OS VETORES PREENCHIDOS");
    textcolor(LIGHTBLUE);gotoxy(29,7);printf("Vetor A ");textcolor(LIGHTRED);gotoxy(29,9);
    for( i = 0; i < tam; i++ ){
        printf(" %d ",Vetor [ i ] );
    }
    getche();
    textcolor(LIGHTBLUE);gotoxy(29,11);printf("Vetor B ");
    textcolor(LIGHTRED);gotoxy(29,13);
    for( i = 0; i < tam; i++ ){
        printf(" %d ",Vet_or [ i ] );
    }
    getche();
    for( i = 0; i < tam; i++ ){
        Vet [ i ] = Vetor [ i ];
        Vet [ i + 5 ] = Vet_or [ i ];
    }
    textcolor(LIGHTBLUE);gotoxy(20,15);printf("Abaixo, a uniao dos dois Vetores ja ordenados");
    ord = 0;
    while ( ord == 0 ){
        ord = 1;
        for ( i = 0; i < V; i++ ){
            if ( Vet [i]  >
            Vet [ ( i + 1 ) ] ){
                aux = Vet [i];
                Vet [i] = Vet [ (i + 1) ];
                Vet [(i + 1)] = aux;
                ord = 0;
            }
        }
    }
    textcolor(LIGHTRED);gotoxy(10,17);
    for( i = 0; i < V; i++ )
        printf(" %d ",Vet [ i ] );getche();system("cls");Janela5();
    textcolor(LIGHTRED);gotoxy(29,3);printf("PROGRAMA UNIAO DE VETORES");
    textcolor(LIGHTBLUE);gotoxy(23,5);printf("ESTES SAO OS NUMEROS COM SEUS REPETENTES");
    textcolor(YELLOW);gotoxy(21,8);
    for (i = 0; i < V; i++) {
        vezes = 1;
        j = i + 1;
        while (j < V)
            if (Vet [j] != Vet [i])
                j++;
            else {
                vezes++;
                V--;
                Vet [j] = Vet [V];
            }
        printf("\n\t\t\t\t");
        printf("O Numero ");
        textcolor(LIGHTRED);printf("%d", Vet [ i ] );
        textcolor(YELLOW);printf(" ocorre" );
        textcolor(LIGHTRED);printf(" %d ", vezes );
        textcolor(YELLOW);printf("vezes" );
    }
    textcolor(LIGHTRED);gotoxy(35,23);printf ("O ROCCO AGRADECE");getche();
    exit(0);
}

Nenhum comentário:

Postar um comentário

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