sábado, 5 de abril de 2014

Programa Fatorial de uma Sequencia III

Excelente programa em Linguagem C
para cálculos de fatoriais de Números entre 1 e 10.
O programa está repleto de recursos em sua entrada de dados onde reprova
qualquer item que não se enquadre, só testar pra ver o excelente funcionamento.




#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int Numero( char *str1 );
int Fatorial_De_Numeros( );
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 Repete_Num( char *str1 ){
int ar [ 11 ];int ascii [ 255 ];size_t i;
for ( i = 0; i < 255; i++ ){
ascii [ i ] = 0;
}
for ( i = 0; i < strlen ( str1 ); i++ ){
ar [ i ] = str1 [ i ];
}
for ( i = 0; i < strlen ( str1 ); i++ ){
if ( ar [ i ] != 32 ){
ascii [ ar [ i ] ]++;
}
}
for ( i = 0; i < 255; i++ )
if ( ascii [ i ] > 1 ){
if( Numero( str1 ) == 0 ){
if ( ascii [ i ] == 0 ){
}  else {textcolor(LIGHTMAGENTA);gotoxy(22,10);
printf("\"%s\" Nao eh Numero!!!", str1 );Sleep(1800);
textcolor(LIGHTGREEN);gotoxy(22,15);printf("Digite uma Sequencia Valida!!!");
getche(); return Fatorial_De_Numeros ( );
}
}
textcolor(LIGHTGRAY);
for ( i = 0; i < 255; i++ )
if ( ascii [ i ] > 1 ){
printf("\n\t\t\tO Numero %c repetiu %d vezes \n", i, ascii [ i ] );
}
textcolor(LIGHTGREEN);gotoxy(22,18);printf("Nao digite Numeros repetidos" );
getche();return Fatorial_De_Numeros ( );
}
textcolor(LIGHTGRAY);gotoxy(22,10);
system("pause");
gotoxy(21,10);printf("                                                    ");
return 1;
}
int Numero( char *str1 ){
unsigned int cont;
for( cont = 0; cont < strlen ( str1 ); cont++ ){
if( str1 [ cont ] < '0' || str1 [ cont ] > '9' )
return 0;
}
return 1;
}
int Digite_String( char *str1 ){
int a;unsigned int i;
do{
a = strlen( str1 );
if ( a >= 6 && a <= 10 ){
textcolor(LIGHTGREEN);gotoxy(22,8);printf("Mostrando a Sequencia que possui %d Numeros", a = strlen( str1 ) );
getche();textcolor(YELLOW);gotoxy(22,10);
for ( i = 0; i < strlen( str1 ); i++ ){;
printf(" %c ", str1 [ i ] );
}
return 1;
}
else{
textcolor(YELLOW);gotoxy(22,10);printf("Voce digitou %d Numeros ", a = strlen( str1 ) );
gotoxy(22,11);printf("A sequencia tem que ser de 6 a 10 Numeros");
}
getche();return Fatorial_De_Numeros ( );

}while( 1 );
return 1;
}
int Fatorial_De_Numeros(){
char *vet;
char num [ 10 ];
vet = ( char* ) malloc ( strlen ( num )* sizeof ( char ) );
unsigned int i;int errado = 1;
int aux, ord, n;
int cont = 1;
int fat = 1;
system("cls");
while( errado == 1 ){
Janela5();
textcolor(LIGHTRED);gotoxy(22,3);printf("PROGRAMA FATORIAL DE UMA SEQUENCIA III");
textcolor(LIGHTBLUE);gotoxy(22,5);printf("\aDigite uma sequencia de 6 a 10 Numeros ");
textcolor(LIGHTBLUE);gotoxy(22,6);printf("\aOu digite [ s ] para sair");
textcolor(YELLOW);gotoxy(26,8);gets( num );fflush(stdin);
if( *num == ( 's' ) || *num == ( 'S' ) ){
textcolor(LIGHTRED);gotoxy(33,17);printf("O ROCCO AGRADECE!");Sleep(1800);
exit(0);
}
n = atoi ( num );
if ( n < 0  ){
textcolor(LIGHTGREEN);gotoxy(25,11);printf("\aNao digite Numeros Negativos");
getche();return Fatorial_De_Numeros ( );
}
Repete_Num( num );
if( Numero( num ) == 0 ){
textcolor(YELLOW);gotoxy(22,10);printf("\"%s\" Nao eh Numero!!!", num );Sleep(1800);
textcolor(LIGHTRED);gotoxy(22,15);printf("Digite uma Sequencia Valida!!!");
getche();system("cls");
}  else errado = 0;
}
Digite_String( num );
for ( i = 0; i < strlen ( num ); i++ ){
n = atoi ( num );
textcolor(LIGHTBLUE);gotoxy(22,12);printf("Numeros Digitados: ");
textcolor(YELLOW);gotoxy(22,14);
for ( i = 0; i < strlen ( num ); i++ ){
aux = n % 10;
n = n / 10;
vet [ i ] = aux;
vet [ i ] = aux;
printf(" %d ", vet [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(22,16);printf("Numeros Armazenadosdos Num Vetor");
textcolor(YELLOW);gotoxy(22,18);
for( i = 0; i < strlen ( num ); i++ ){
printf("  %d",vet [ i ] );
}
}
getche( );
textcolor(LIGHTBLUE);gotoxy(22,20);printf("Numeros Ordenados: ");
ord = 0;
while ( ord == 0 ){
ord = 1;
for ( i = 0; i < strlen ( num + 1 ); i++ ){
if ( vet [ i ]  >
vet [ ( i + 1 ) ] ){
aux = vet [ i ];
vet [ i ] = vet [ ( i + 1 ) ];
vet [ ( i + 1 ) ]  = aux;
ord = 0;
}
}
}
textcolor(YELLOW);gotoxy(22,22);
for( i = 0; i < strlen ( num ); i++ )
printf(" %d ",vet [ i ] );
getche();system("cls");
Janela5();
textcolor(LIGHTRED);gotoxy(22,3);printf("PROGRAMA FATORIAL DE UMA SEQUENCIA III");
for ( i = 0; i  < strlen ( num ); i++ ){
while ( cont <= vet [ i ] ){
fat *= cont;
cont += 1;
}
textcolor(LIGHTBLUE);printf("\n\n\t Fatorial de ");Sleep(500);
textcolor(LIGHTRED);printf(" %d ", vet [ i ] );Sleep(500);
textcolor(LIGHTBLUE);printf(" Equivale a ");Sleep(500);
textcolor(LIGHTRED);printf(" %d ", fat );Sleep(500);
}
textcolor(LIGHTRED);gotoxy(33,23);printf ("O ROCCO AGRADECE");getche();exit(0);
getche();free( vet );exit(0);
return(0);
}
int main(){
system ("title PROGRAMA FATORIAL DE UMA SEQUENCIA III");
Fatorial_De_Numeros ( );
}