domingo, 3 de fevereiro de 2013

Gerando números aleatórios em matriz estática

#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <conio.h>
int main(){
    system ("title GERANDO NUMEROS ALEATORIOS EM MATRIZ ESTATICA");
    srand ( time ( NULL ) );
    int a1 [ 10 ] [ 10 ], n, m, i, j = 0, x = 0, y = 0; int ord = 0, aux, vezes;
    int VET [ 100 ];
    system("cls");
    textcolor(LIGHTRED);gotoxy(25,3);printf("GERANDO NUMEROS ALEATORIOS EM MATRIZ");
    textcolor(YELLOW);gotoxy(24,5);printf("Programa desenvolvido por:");
    textcolor(LIGHTCYAN);gotoxy(52,5);printf("Samuel Lima");
    textcolor(LIGHTBLUE);gotoxy(35,7);printf("sa_sp10@hotmail.com");
    textcolor(WHITE);gotoxy(30,9);printf("DIGITE O NUMEROS DE LINHAS:  ");
    textcolor(LIGHTRED);scanf ( "%d",&n );fflush (stdin);
    textcolor(WHITE);gotoxy(30,11);printf("DIGITE O NUMERO DE COLUNAS:  ");
    textcolor(LIGHTRED);scanf ( "%d",&m );fflush (stdin);
    system("cls");
    textcolor(LIGHTRED);gotoxy(25,3);printf("GERANDO NUMEROS ALEATORIOS EM MATRIZ");
    textcolor(LIGHTBLUE); gotoxy(36,5);printf("GERANDO A MATRIZ...");
    gotoxy(20,6);textcolor(YELLOW);
    for ( i = 1; i <= n; i++ ){
        printf("\n\t\t");
        for ( j = 1; j <= m; j++ ){
            a1 [i] [j] = rand () % 10; Sleep(50);
            VET [y] =  a1 [i] [j];
            y++;
            printf(" %3d ", a1 [i] [j]);
        }
        printf("\n");
    }
    textcolor(LIGHTRED);gotoxy(25,3);printf("GERANDO NUMEROS ALEATORIOS EM MATRIZ");
    textcolor(LIGHTBLUE); gotoxy(36,5);printf("MATRIZ  BEM  GERADA");
    textcolor(LIGHTGRAY);gotoxy(32,23);printf("PRESSIONE QUALQUER TECLA");
    getche();
    system("cls");
    textcolor(LIGHTRED);gotoxy(25,3);printf("GERANDO NUMEROS ALEATORIOS EM MATRIZ");
    textcolor(LIGHTBLUE);gotoxy(22,5);printf("MOSTRANDO OS NUMEROS GERADOS DESORDENADOS");
    gotoxy(2,7);textcolor(YELLOW);
    for ( int x = 0; x < y; x++ ){
        printf(" %d ", VET [x] ); Sleep(20);
    }
    Sleep(800);
    textcolor(LIGHTBLUE);gotoxy(25,11);printf("MOSTRANDO EM ORDEM OS NUMEROS GERADOS ");
    ord = 0;
    while(ord == 0){
        ord = 1;
        for(x = 0; x <= y; x++){
            if( VET [x]  > VET [(x + 1)]){
                aux = VET [x];
                VET [x] = VET [(x + 1)];
                VET [(x + 1 )] = aux;
                ord = 0;
            }
        }
    }
    textcolor(YELLOW);gotoxy(2,13);
    for(int x = 0; x < y ; x++){
        printf(" %d ", VET [x]);
    }
    textcolor(LIGHTGRAY);gotoxy(32,17);printf("PRESSIONE QUALQUER TECLA");
    getche();
    system("cls");
    textcolor(LIGHTRED);gotoxy(25,3);printf("GERANDO NUMEROS ALEATORIOS EM MATRIZ");
    textcolor(LIGHTBLUE);gotoxy(32,5);printf("sa_sp10@hotmail.com");
    textcolor(LIGHTGREEN);gotoxy(30,7);printf("NUMEROS ORDENADOS E REPETIDOS");
    textcolor(YELLOW);gotoxy(3,9);
    for(x = 0; x < y ; x++){
        printf(" %d ", VET [x]);
    }
    getche();
    printf("\n");
    for (x = 0; x < y; x++) {
        vezes = 1;
        j = x + 1;
        while (j < y)
            if (VET[j] != VET[x])
                j++;
            else {
                vezes++;
                y--;
                VET[j] = VET[y];
            }
        printf("\nO VALOR %d OCORRE %d VEZES", VET[x], vezes);
    }
    Sleep(800);
    textcolor(LIGHTGREEN);gotoxy(37,12);printf("NUMEROS GERADOS SEM OS REPETIDOS");
    textcolor(YELLOW);gotoxy(38,14);
    for (x = 1; x < y; x++){
        printf(" %d ", VET[x]);
    }
    textcolor(LIGHTRED);gotoxy(44,16);printf("\aO ROCCO AGRADECE");
    getche();
}

Nenhum comentário:

Postar um comentário

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