sexta-feira, 8 de abril de 2016

Vetor - invocando vetor

Depois de dois mêses sem programar apresento este segundo
programa selando meu retorno,"Vetor - invocando vetor".
Dois vetores pré-definidos, e duas funções de embaralhamentos,
são os pontos principais deste programa.
Um vetor escolhe através de um número aleatório automático,
quantos elementos serão imprimidos pelo outro.
Isto acontece dentro de um laço while(); que graças aos
incrementos de duas variáveis, um número é escolhido por vez
no vetor que indica a quantidade que o outro deve imprimir.
O tempo curto e a pressa de encerrar por hoje, aliás não foi fácil
fazer isto acreditam? não me permite fazer mais comentários.




Veja abaixo o código do programa:



#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#define tam 9
#define dim 4
void got_color ( int tam_lin_ini, int tam_lin_fim,
         int tam_ini_col, int tam_fim_col, int a, int b ) {
     int i, e;
     if ( a >= 1 && a <= 16 ){
         textcolor ( a );
     }
     if ( b >= 1 && b <= 16 ){
         textbackground ( b );
     }
     for ( i = tam_lin_ini; i <  tam_lin_fim; i++ ) {
         for ( e = tam_ini_col; e < tam_fim_col; e++ ){
              gotoxy ( e, i );
              printf(" ");
         }
     }
}
void emb_lhar ( int vetor [ tam ] ) {
     int i, temp;
     int y = y;
     srand ( time ( NULL ) );
     for ( i = 0; i < tam; i++ ) {
         y = rand ( ) % tam;
         temp = vetor [ i ];
         vetor [ i ] = vetor [ y ];
         vetor [ y ] = temp;
     }
}
void emblhar( int vet [ dim ] ) {
     int i, temp;
     int r = r;
     srand ( time ( NULL ) );
     for ( i = 0; i < dim; i++ ) {
         r = rand ( ) % dim;
         temp = vet [ i ];
         vet [ i ] = vet [ r ];
         vet [ r ] = temp;
     }
}
int main(){
     system ("title VETOR - INVOCANDO VETOR");
     int vetor [ tam ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     int vet [ dim ] = { 2, 3, 4, 5 };
     int b;
     int a = 1;
     int i, x = 0;
     emblhar ( vet );
     for ( i = 0; i < tam; i++){
         for ( i = 0; i < dim; i++ ) {
              do{
                   got_color ( 2, 25, 3, 79, 2, 15 );//Moldura
                   a = vet [ i ];
                   textcolor(LIGHTRED);gotoxy(31,3);
                   printf("VETOR - INVOCANDO VETOR");
                   textcolor(LIGHTBLUE);gotoxy(31,5);
                   printf("Vou imprimir ");
                   textcolor(LIGHTRED);printf("%d", a );
                   textcolor(LIGHTBLUE);printf(" elementos" );
                   Sleep(800);
                   textcolor(LIGHTBLUE);
                   emb_lhar ( vetor );
                   textcolor(LIGHTRED);gotoxy(31,7);
                   for ( b = 1; b <= a; b++){
                        printf(" %d ", vetor [ b ] );
                   }
                   i++;
                   x++;
                   textcolor(LIGHTRED);gotoxy(31, 9);
                   printf("%da", x + 0 );
                   textcolor(BLACK);printf(" Impressão");
                   Sleep(1800);
                   gotoxy ( 31 , 5 );clreol ( );
                   gotoxy ( 31 , 7 );clreol ( );
                   gotoxy ( 31 , 9 );clreol ( );
                   if ( x == 9 ){
                        textcolor(LIGHTBLUE);gotoxy(31, 11);
                        printf("Imprimido corretamente");
                        Sleep (1800);
                        textcolor ( LIGHTRED );gotoxy ( 26, 15 );
                        printf ( "Por: " );
                        textcolor(LIGHTBLUE);
                        printf ( "Samuel Lima" );
                        textcolor(BLACK);gotoxy ( 26, 16 );
                        printf ( "sa_sp10@hotmail.com" );
                        Sleep (1800);textcolor(LIGHTRED);gotoxy ( 37, 23 );
                        printf ( "MUITO OBRIGADO" );
                        getche();
                        exit(0);
                   }
                   break;
              }while ( 1 );
              i = i - 1;
         }
     }
     return 0;
}

 

Nenhum comentário:

Postar um comentário

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