segunda-feira, 7 de abril de 2014

Programa Múltiplos de Um Número

Qualquer número multiplicado pela sequência dos números naturais, obtem - se os seus Múltiplos,
Veja abaixo a sequência dos Números Múltiplos de 2 até 5:

2 x 0 = 0
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10

E assim vai, até onde você quizer.

Portanto 2, 4, 6, 8 e 10 são Múltiplos de { 2 }, Partindo desta lógica ficou fácil criar este programa em linguagem C.




Veja o Código do programa abaixo:

#include <stdio.h>
#include <conio.h>
#define tam 10
int main ( ) {
     int a, b, c, i, j = 0, num;
     system ( "title PROGRAMA MULTIPLOS DE UM NUMERO " );
     while ( 1 ) {
         system ( "cls" );
         textcolor ( LIGHTRED );
         gotoxy ( 27 , 3 );
         printf ( "PROGRAMA MULTIPLOS DE UM NUMERO " );
         textcolor ( LIGHTBLUE );
         gotoxy ( 20 , 5 );
         printf ( "Digite um intervalo" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 20 , 7 );
         printf ( "De: " );
         textcolor ( YELLOW );
         scanf ( "%d" , &a );
         fflush ( stdin );
         textcolor ( LIGHTGREEN );
         gotoxy ( 20 , 9 );
         printf ( "Ate: " );
         textcolor ( YELLOW );
         scanf ( "%d" , &b );
         fflush ( stdin );
         do {
              system ( "cls" );
              textcolor ( LIGHTRED );
              gotoxy ( 27 , 3 );
              printf ( "PROGRAMA MULTIPLOS DE UM NUMERO " );
              textcolor ( LIGHTBLUE );
              gotoxy ( 16 , 5 );
              printf ( "Digite um numero entre 1 e %d [ Zero para Sair ] " ,
                        tam );
              scanf ( "%d" , &c );
              fflush ( stdin );
              if ( c < 0 || c > tam ) {
                   textcolor ( LIGHTGRAY );
                   gotoxy ( 24 , 11 );
                   printf ( "\aNumero Acima de 0 e menor que %d " , tam );
                   getche ( );
                   system ( "cls" );
              }
         } while ( ( c < 0 ) || ( c > tam ) );
         if ( c == 0 ) {
              printf ( "\n\nO ROCCO AGRADECE" );
              Sleep ( 1800 );
              exit ( 0 );
         }
         textcolor ( LIGHTGREEN );
         gotoxy ( 22 , 7 );
         printf ( "Veja abaixo os Multiplos de %d ate %d" , c , b );
         textcolor ( YELLOW );
         gotoxy ( 2 , 9 );
         for ( i = a; i <= b ; i++ )
              if ( ! ( i % c ) ) {
                   printf ( "%d " , i );
                   j++;
              }
         textcolor ( LIGHTBLUE );
         printf ( "\n\n\t\t\t" );
         printf ( "Entre %d e %d  Temos %d Multiplos de %d" , a , b , j , c );
         getche ( );
         for ( num = 0; ; num++ ) {
              textcolor ( LIGHTCYAN );
              gotoxy ( 20 , 17 );
              printf ( "Digite: [ 1 para Repetir ou Negativo para sair ]\n" );
              gotoxy ( 39 , 21 );
              scanf ( "%d" , &num );
              fflush ( stdin );
              if ( num < 0 ) {
                   textcolor ( LIGHTRED );
                   gotoxy ( 35 , 21 );
                   printf ( "O ROCCO AGRADECE" );
                   Sleep ( 1800 );
                   exit ( 0 );
              }
              if ( num == 1 ) {
                   main ( );
              } else {
                   textcolor ( LIGHTBLUE );
                   gotoxy ( 36 , 21 );
                   printf ( "\aOPCAO ERRADA" );
                   Sleep ( 1800 );
                   textcolor ( LIGHTBLUE );
                   gotoxy ( 36 , 21 );
                   printf ( "               " );
              }
         }
     }
}

Nenhum comentário:

Postar um comentário

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