Buscar este blog

viernes, 27 de marzo de 2015

Tacometro, arduino, led infrarrojo y fototransistor

#include <LiquidCrystal.h> // Se declara la libreria de la pantalla

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);   // Se inicializan los pines que usara

const int  releReedPin = 2;   // Entrada del pulso
int estadoRele = 1;           // Estado inicial del pulso
int ultimoEstadoRele = 1;     // Estado anterior del pulso que ira cambiando
long tiempo_anterior = 0;      // Tiempo anterior medido
long tiempo_una_rev = 0;       // Tiempo de una revolucion
unsigned long tiempo_ahora;    // Tiempo actual medido
long rpm;                      // Valor de RPM primario
long vueltas;                 // Valor de RPM secundario

void setup()
{
  // Se inicializa la pantalla y se declara el pulso como entrada ademas se imprime la leyenda velocidad en la lcd
  pinMode(releReedPin, INPUT);
    lcd.begin(16,2);
    lcd.print("   Velocidad ");
}


void loop()
{
  estadoRele = digitalRead(releReedPin);      // Lee el estado del rele
 
  // Compara el estado del rele con el estado previo
  if (estadoRele != ultimoEstadoRele)
  {
    // Si el estado ha cambiado realiza el calculo de las RPM y lo despliega
    if (estadoRele == LOW)
    {
      tiempo_ahora =millis();
      tiempo_una_rev = tiempo_ahora - tiempo_anterior;
      rpm = 60000 / tiempo_una_rev; // 1 minuto = 60000 ms
      lcd.setCursor(0,1);
      lcd.print("     ");
      lcd.setCursor(0,1);
      lcd.print(rpm);
      lcd.setCursor(6,1);
      lcd.print(" RPM");
     
     
    }
    else {
      // Si el estado actual es HIGH pasa de ON a OFF  y se despliega el valor de RPM secundario que seraia el valor anterior
      vueltas=rpm;
      lcd.setCursor(0,1);
      lcd.print("     ");
      lcd.setCursor(0,1);
      lcd.print(vueltas);
      lcd.setCursor(6,1);
      lcd.print(" RPM");
      tiempo_anterior = tiempo_ahora;
    }
  }
  // Guarda el estado actual como ultimo estado
  ultimoEstadoRele = estadoRele;
}

domingo, 8 de marzo de 2015

Contador 20 BITS en VHDL

----------------------------------------------------------------------------------
-- CONTADOR
--  contador ascendente/descendente de n bits…
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Contador is
    Port ( CLOCK : in  STD_LOGIC;
           CLC_E : in  STD_LOGIC;
           A, R : in  STD_LOGIC;
           S : buffer  STD_LOGIC_VECTOR(20 DOWNTO 0));
end Contador;

architecture COUNT of Contador is
signal temporal: std_logic;
signal contador: integer range 0 to 49999999:=0;
signal Salida: std_logic;
begin
divisor_frecuencia: process(R, clock)
begin
if(R='1') then
temporal<='0';
contador<=0;
elsif (rising_edge(clock)) then
if(contador=49999999) then
temporal<= not(temporal);
contador<=0;
else
contador<=contador+1;
end if;
end if;
end process;
Salida<=temporal;

counter: process (R, Salida)
begin
if (R ='1') then
S<="000000000000000000000";
elsif (Salida'EVENT and Salida ='1' and CLC_E ='0')then
if (A='1') then
S<=S+1;
else
S<=S-1;
      end if;
   end if;
end process;
end COUNT;


--------------------------------------------------------------------------------------------------------------------------

NET "R" LOC = "T15" | IOSTANDARD = LVCMOS33 | PULLDOWN;
NET "CLOCK" LOC = E12;
NET "A" LOC = T9;
NET "CLC_E" LOC = V8;
NET "S[20]" LOC = AA6;
NET "S[19]" LOC = AA4
NET "S[18]" LOC = AB3
NET "S[17]" LOC = AA3
NET "S[16]" LOC = AB2;
NET "S[15]" LOC = Y18;  
NET "S[14]" LOC = W18;  
NET "S[13]" LOC = V17;   
NET "S[12]" LOC = W17;  
NET "S[11]" LOC = AA21;  
NET "S[10]" LOC = AB21;
NET "S[9]" LOC = AA19;   
NET "S[8]" LOC = AB19;  
NET "S[7]" LOC = R20;  
NET "S[6]" LOC = T19;  
NET "S[5]" LOC = U20;  
NET "S[4]" LOC = U19; 
NET "S[3]" LOC = V19; 
NET "S[2]" LOC = V20; 
NET "S[1]" LOC = Y22;
NET "S[0]" LOC = W21; 


Contador 0 - 15 VHDL (solo simulacion)

----------------------------------------------------------------------------------

----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Problema3 is
    Port ( Q : BUFFER  STD_LOGIC_vector(3 DOWNTO 0):="0000";
       CLOCK : IN  STD_LOGIC
 );
end Problema3;

architecture Contador of Problema3 is
BEGIN
counter:   PROCESS (Q, CLOCK)
BEGIN
IF (CLOCK'EVENT AND CLOCK ='1')THEN
Q<=Q+1;

   END IF;
   END PROCESS;
end Contador;

Implementación 7 funciones de tranferencia en VHDL

----------------------------------------------------------------------------------
-- D C B A | F0 | F1 | F2 | F3 | F4 | F5 | F6 | F7
-- 0 0 0 0 | 1  | 1  | 1  | 1  | 1  | 1  | 1  | 1
-- 0 0 0 1 | 0  | 1  | 1  | 1  | 1  | 1  | 1  | 1
-- 0 0 1 1 | 0  | 0  | 0  | 1  | 1  | 1  | 1  | 1
-- 0 1 0 0 | 0  | 0  | 0  | 0  | 1  | 1  | 1  | 1
-- 0 1 0 1 | 0  | 0  | 0  | 0  | 0  | 1  | 1  | 1
-- 0 1 1 0 | 0  | 0  | 0  | 0  | 0  | 0  | 1  | 1
-- 0 1 1 1 | 0  | 0  | 0  | 0  | 0  | 0  | 0  | 1
-- 1 0 0 0 | 0  | 0  | 0  | 0  | 0  | 0  | 0  | 0
-- 1 0 0 1 | 0  | 0  | 0  | 0  | 0  | 0  | 0  | 1
-- 1 0 1 0 | 0  | 0  | 0  | 0  | 0  | 0  | 1  | 1
-- 1 0 1 1 | 0  | 0  | 0  | 0  | 0  | 1  | 1  | 1
-- 1 1 0 0 | 0  | 0  | 0  | 0  | 1  | 1  | 1  | 1
-- 1 1 0 1 | 0  | 0  | 0  | 1  | 1  | 1  | 1  | 1
-- 1 1 1 0 | 0  | 0  | 1  | 1  | 1  | 1  | 1  | 1
-- 1 1 1 1 | 0  | 1  | 1  | 1  | 1  | 1  | 1  | 1
-- Considere los siguientes aspectos:
-- • No utilice librerías ni paquetes
-- • Utilice entradas y salidas tipo bit
-- • Obtenga las ecuaciones de F0 hasta F7 utilizando la estructura when-else    
--
----------------------------------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity Problema2 is
    Port ( A : in  BIT;
           B : in  BIT;
           C : in  BIT;
           D : in  BIT;
           F0 : out  BIT;
           F1 : out  BIT;
           F2 : out  BIT;
           F3 : out  BIT;
           F4 : out  BIT;
           F5 : out  BIT;
           F6 : out  BIT;
           F7 : out  BIT);
end Problema2;

architecture Flujo of Problema2 is
begin
f0<='1'  when( d='0'    and   c='0'    and   b='0'    and   a='0')   else '0';

f1<='1'  when( d='0'    and   c='0'    and b='0'    and   a='0')   else '1'
         when( d='0'    and   c='0'    and b='0'    and   a='1')   else '1'
     when( d='1'    and   c='1'    and b='1'    and   a='1')   else '0';

f2<='1'  when( d='0'    and   c='0'    and b='0'    and   a='0')   else '1'
         when( d='0' and c='0' and b='0' and a='1') else '1'
     when( d='0' and c='0' and b='1' and a='0') else '1'
     when( d='1' and c='1' and b='1' and a='0') else '1'
     when( d='1' and c='1' and b='1' and a='1') else '0';

f3<='1' when( d='0' and c='0' and b='0' and a='0') else '1'
         when( d='0' and c='0' and b='0' and a='1') else '1'
     when( d='0' and c='0' and b='1' and a='0') else '1'
     when( d='0' and c='0' and b='1' and a='1') else '1'
     when( d='1' and c='1' and b='0' and a='1') else '1'
     when( d='1' and c='1' and b='1' and a='0') else '1'
     when( d='1' and c='1' and b='1' and a='1') else '0';

f4<='1' when( d='0' and c='0' and b='0' and a='0') else '1'
         when( d='0' and c='0' and b='0' and a='1') else '1'
     when( d='0' and c='0' and b='1' and a='0') else '1'
         when( d='0' and c='0' and b='1' and a='1') else '1'
     when( d='0' and c='1' and b='0' and a='0') else '1'
     when( d='1' and c='1' and b='0' and a='0') else '1'
     when( d='1' and c='1' and b='0' and a='1') else '1'
     when( d='1' and c='1' and b='1' and a='0') else '1'
     when( d='1' and c='1' and b='1' and a='1') else '0';

f5<='0' when( d='0' and c='1' and b='1' and a='0') else '0'
         when( d='0' and c='1' and b='1' and a='1') else '0'
     when( d='1' and c='0' and b='0' and a='0') else '0'
     when( d='1' and c='0' and b='0' and a='1') else '0'
     when( d='1' and c='0' and b='1' and a='0') else '1';

f6<='0' when( d='0' and c='1' and b='1' and a='1') else '0'
      when( d='1' and c='0' and b='0' and a='0') else '0'
      when( d='1' and c='0' and b='0' and a='1') else '1';

f7<='0' when( d='1' and c='0' and b='0' and a='0') else '1';
end Flujo;


--------------------------------------------------------------------------------------------------------------------------

NET "F0" LOC = W21;
NET "F1" LOC = Y22;
NET "F2" LOC = V20;
NET "F3" LOC = V19;
NET "F4" LOC = U19;
NET "F5" LOC = U20;
NET "F6" LOC = T19;
NET "F7" LOC = R20;
NET "A" LOC = V8;
NET "B" LOC = U10;
NET "C" LOC = U8;
NET "D" LOC = T9;

# PlanAhead Generated physical constraints


Implementación de funciones de tranferencia en VHDL

----------------------------------------------------------------------------------

-- A | B | f0 | f1
-- ---------------
-- 0 | 0 | 0  | 0
-- 0 | 1 | 1  | 0  
-- 1 | 0 | 1  | 1
-- 1 | 1 | 1  | 1    
--


----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity Problema1 is
    Port ( A : in  STD_LOGIC;
           B : in  STD_LOGIC;
           F0 : out  STD_LOGIC;
           F1 : out  STD_LOGIC);
end Problema1;

architecture Funcional of Problema1 is
begin
process(A,B)
begin
if(A='0' and B='0')then
F0<='0';
else
F0<='1';
end if;
if(A='0') then
F1<='0' ;
else
F1<='1';
end if;
end process;
end Funcional;

--------------------------------------------------------------------------------------------------------------------------

# PlanAhead Generated physical constraints

NET "A" LOC = U10;
NET "B" LOC = V8;
NET "F0" LOC = T19;
NET "F1" LOC = R20;


Control de atura de un objeto usando sensor ultrasonico, lm35 y secadora de pelo en ARDUINO

#include <LiquidCrystal.h> // Incluir esta libreria para poder usar el lcd

int Ana1ogica = A0; // Entrada analogica de LM35
LiquidCrystal lcd(12,11,5,4,3,2); // Definimos las salidas de la pantalla LCD
int Temp = 0; // Se inicializa la temperatura en cero
char Grados = '°C'; // Unidad de medida de la temperatura
int triger=7; // Pulso
int echo=8; // Echo recivido
int encendido=10; // Control de encedendido del aire

void setup()
{
  Serial.begin(9600);    
  lcd.begin(16,2);
  pinMode(13,OUTPUT);
  digitalWrite(13, HIGH); //Activamos la retroiluminacion
}

void loop()
{
  pinMode(encendido, OUTPUT);     // Ponemos el encendido como salida
  delayMicroseconds(2);
  digitalWrite(encendido, HIGH);
  // Medicion de distancia con sensor ultrasonico
  long pulso, inches, cm, altura;  // Variables de medicion
  pinMode(triger, OUTPUT);     // Ponemos el triger como salida
  digitalWrite(triger, LOW);  // Lo inicializamos bajo
  delayMicroseconds(2);    // Esperamos 2 microsegundos
  digitalWrite(triger, HIGH);   // Lo activamos
  pinMode(echo, INPUT);      // Ponemos el echo como entrada
  pulso = pulseIn(echo, HIGH);  // Medimos el pulso de salida del sensoR
  // Calculamos la temperatura
  Temp = analogRead(Ana1ogica); // Leemos el valor de la entrada analogica
  Temp = Temp * 0.48828125;  // Escalamos la señal a grados centigrados
  // Convertimos el tiempo en distancia
  cm = microsecTocm(pulso);
  //altura=49.5-cm;

 lcd.clear();
  // Mostramos los grados en el serial
  Serial.print("Grados: ");
  Serial.print(Temp);
  //Serial.print(Grados);
  Serial.println("°C");
  // Mostramos la distancia en el serial
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

  // Mostramos los grados en la pantalla LCD
  lcd.setCursor(0,0);          
  lcd.print("Temperatura: ");
  lcd.setCursor(12,0);
  lcd.print(Temp);
  lcd.setCursor(15,0);
  lcd.print(Grados);

  // Mostramos la distancia en la pantalla lcd
  lcd.setCursor(0,1);
  lcd.print("Altura: ");
  lcd.setCursor(8,1);
  lcd.print(cm);
  lcd.setCursor(11,1);
  lcd.print("cm");


  // Lo apagamos si la temperatura sobrepasa los 30 grados
  if (Temp >= 30)
  {
  delayMicroseconds(1000);
  digitalWrite(encendido, LOW);
  delayMicroseconds(10000);
  if(Temp<30)
  {
   delayMicroseconds(1000);
   digitalWrite(encendido, HIGH);
  }
}

  // Lo apagamos si la altura sobrepara los limites menor o mayor
if(cm <= 6.5 || cm >=21)
  {
  lcd.clear();
  delayMicroseconds(2);
  digitalWrite(encendido, LOW);
  lcd.setCursor(0,0);
  lcd.print("Sistema apagado.");
  lcd.setCursor(0,1);
  lcd.print(" Reiniciando...");
  }
  delay(1000);
}
// Por ultimo las funciones que convierten el tiempo en distancia
long microsecToin(long microsec)
{ return microsec / 74 / 2; }
long microsecTocm(long microsec)
{ return microsec / 29 / 2; }

Funciones para ordenar arreglos

#include <iostream>
#include <windows.h>

using namespace std;

void selectSort(int A[], int n);
void bubbleSort(int A[], int n);
int binarySearch(int A[], int n, int val);

int main()
{
  int A[4]={3, 1, 0, 5};
  int B[4]={3, 1, 0, 5};

  selectSort(A , 4);
  cout<<"\n Selection Sort:"<<endl;
  for(int i=0 ; i<4 ; i++)
  {
     cout<<"\n";
     cout<<A[i];
  }
  cout<<"\n"<<endl;
  cout<<" ";system("PAUSE");
  bubbleSort(B , 4);
  cout<<"\n Bubble Sort:"<<endl;
  for(int j=0 ; j<4 ; j++)
  {
     cout<<"\n";
     cout<<B[j];
  }
  cout<<"\n"<<endl;
  cout<<" ";system("PAUSE");
  binarySearch(A, 4, 3);
  cout<<"\n Binary Search:"<<endl;

    return 0;
}
//------------------------------------------------------------------------------------------------------------------------
void selectSort (int A[], int n)
{ int minimo, indice;
    for(int i=0 ; i<n ; i++)
    { indice=i;
        for(int j=i+1 ; j<n ; j++)
        {
            if(A[j]<A[indice])
            {
              indice=j;
              if(indice != i)
              {
                  minimo=A[i];
                  A[i]=A[indice];
                  A[indice]=minimo;
     }}}}}

//------------------------------------------------------------------------------------------------------------------------

void bubbleSort(int A[], int n)
{ int val;
  bool mov=true;
  int j=0;
  while(mov)
  { mov=false;
    j++;
    for(int i=0 ; i<(n-j) ; i++)
    {
        if(A[i]>A[i+1])
        {
            val=A[i];
            A[i]=A[i+1];
            A[i+1]=val;
            mov=true;
        }}}}
//------------------------------------------------------------------------------------------------------------------------

int binarySearch(int A[], int in, int fin, int val)
{ int i=(in+fin)/2;
    if(in>fin)
    {
       return -1;
    }
    if(val==A[i])
    {
        return i;
    }
    else if(val<A[i])
    {
        return binarySearch(A, in, i-1, val);
    }
    else if(val>A[i])
    {
       return binarySearch(A, i+1, fin, val);
    }
}

Programa triángulos de caracteres

Programa que solicita un numero N al usuario y produce como salida la siguiente
      salida:
             Si N=0, el programa solicita de nuevo un número
             Si N>0, imprime la siguiente secuencia
                     Ejem: N= 3
                     ***
                     **
                     *
             Si N<0, imprime la siguiente secuencia
                     Ejem: N=  -3
                     ***
                      **
                       *                                                                    

#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;

int N, l1, l2, e;
int main()
{
    do{
    cout<<"\n"<<" Ingrese un numero entero: ";
    cin>>N;
    if(N>0)
    {   cout<<"\n"<<endl;
        for(l1=0 ; l1<=(N-1) ; l1=l1+1)
        {for(l2=1 ; l2<=(N-l1) ; l2=l2+1)
         {cout<<"*";}
          cout<<endl;}}
    if(N<0)   // Hay un error y no reconoce numeros negativos, pero no pude encontrarlo, si se cambia la condicion se despliega bien

    {   cout<<"\n"<<endl;
        for(l1=0 ; l1<=(N-1) ; l1=l1+1)
        {for(e=0 ; e<l1 ; e=e+1)
         {cout<<" ";}
         for(l2=1 ; l2<=(N-l1) ; l2=l2+1)
         {cout<<"*";}
          cout<<endl;}}
    if(N==0)
    {cout<<"\n"<<" Introduzca un numero diferente de cero."<<"\n"<<endl;
     system("PAUSE");
     system("CLS");}
    }while(N==0);
    return 0;
}

Programa que le pide números al usuario y solo se detiene una vez que el usuario ingresa el número -999

Programa que le pide números al usuario y solo se detiene una vez que el usuario
      ingresa el número -999. Después, el programa imprime el valor del mínimo, el máximo y el
      promedio.
                                                                                             
#include <iostream>
#include <conio.h>
using namespace std;

float n, suma=999, mayor=0, menor=0, val, cont, prom;
int main()
{
    cout<<"\n\tEl programa se detendra solo si ingresa el numero -999."<<endl;
    do
    {
       cout<<"\n Ingrese un numero: ";
       cin>>n;
       val=n;
       if(n>=mayor)
       {mayor=n;}
       if(n<=menor && n!=-999)
       {menor=n;}
       cont=cont+1;
       suma=suma+n;
       }while(val!=-999);
    prom=suma/cont;
    cout<<"\n\n\t\t\t\tEl numero mayor es: "<<mayor<<endl;
    cout<<"\n\t\t\t\tEl numero menor es: "<<menor<<endl;
    cout<<"\n\t\t\t\tEl promedio es: "<<prom<<endl;
    return 0;
}

Programa que le solicita números al usuario

Programa que le solicita números al usuario. Cada vez que se ingresa un número se
      despliega el cuadrado del número, y el programa solo se detiene cuando el usuario ingresa un
      número que sea múltiplo de 7.



#include <iostream>
using namespace std;

int n, cuad, mult;
int main()
{
    mult=1;
    while(mult!=0)
    {
      cout<<"\n Ingrese un numero: ";
      cin>>n;
      mult=(n%7);
      cuad=n*n;
      cout<<"\n El cuadrado del numero es: "<<cuad<<endl;
    }
    return 0;
}

Programa que le pide al usuario 10 enteros y como salida imprime el mínimo y el número de veces que se ingresó dicho valor

Programa que le pide al usuario 10 enteros y como salida imprime el mínimo y el
      número de veces que se ingresó dicho valor

#include <iostream>
#include <conio.h>
using namespace std;

int n, mini=10,cont=0, i=1, val_ant;
int main()
{
    cout<<"\n Ingrese 10 numeros enteros: "<<endl;
    for(i ; i<=10 ; i=i+1)
    {
        cout<<" Numero "<<i<<" : ";
        cin>>n;
        if(n<=mini)
        {
          mini=n;
          cont=cont+1;
          if(mini<val_ant)
          {cont=cont-cont+1;}
        }
        val_ant=mini;
    }
    cout<<"\n El numero menor es: "<<"'"<<mini<<"'"<<" y se ingreso "<<"'"<<cont<<"'"<<" veces.\n"<<endl;
    return 0;
}

Programa que toma dos fechas, especificadas en día/mes/ año y calcula la diferencia entre los dos en días

Programa que toma dos fechas, especificadas en día/mes/ año y calcula la diferencia
      entre los dos en días totales (asumir que no hay años bisiestos).  */

#include <iostream>
#include <cmath>
using namespace std;

int dia1, mes1, anio1, dia2, mes2, anio2, dias, resmes;
int main()
{
    cout<<"\n"<<" Ingrese una fecha en el orden dia, mes, anio: ";
    cin>>dia1;
    cin>>mes1;
    cin>>anio1;
    cout<<"\n"<<" Ingrese una segunda fecha en el orden dia, mes, anio: ";
    cin>>dia2;
    cin>>mes2;
    cin>>anio2;
    resmes=abs(mes1-mes2);
    dias=abs(365*(anio1-anio2))+abs(resmes*(30.41666667))+abs(dia1-dia2);
    cout<<"\n"<<" La diferencia en dias es: "<<dias<<" dias"<<endl;
    return 0;
}


Nota: no es exacto.

Programa que calcula la suma de los cuadrados de n números naturales

Programa que calcula la suma de los cuadrados de n números naturales, donde el valor de n lo especifica el usuario


// Pprograma A, con ciclo for.
#include <iostream>
#include <stdlib.h>
using namespace std;

int n, cuad, suma, num;
int main()
{
    cout<<"\n"<<" Introdusca una cantidad de numeros: ";
    cin>>n;
    if(n<0)
    {
        system("CLS");
        cout<<"\n"<<" Introdusca un numero positivo"<<endl;
        cout<<"\n"<<endl;
        system("PAUSE");
        system("CLS");
        cout<<"\n"<<" Introdusca una cantidad de numeros: ";
        cin>>n;
        if(n>=0)
    {
      for(num=0 ; num<=(n+1) ; num=num+1)
    {
        cuad=num*num;
        suma=suma+cuad;
    }
    cout<<"\n"<<" La suma de los numeros es: "<<suma<<endl;
    }
    }
    else if(n>=0)
    {
      for(num=0 ; num<=n ; num=num+1)
    {

        cuad=num*num;
        suma=suma+cuad;
    }
    cout<<"\n"<<" La suma de los numeros es: "<<suma<<endl;
    }
    return 0;
}

Imprime todos los números pares, impares o primos entre el 1 y el 100

Programa que imprime todos los números pares, impares o primos entre el 1 y el 100
      en base a una decisión aleatoria al inicio del programa.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;

int num, pares, impares, primos;
int main()
{
   cout<<"\n"<<" Presione enter para proceder..."<<endl;
   cin.get();
   srand(time(0));
   num=1+(rand()%3);
if(num == 2)
{   cout<<"Numeros pares:"<<endl;
    for(pares=2; pares<=100; pares=pares+2)
    {   cout<<pares<<", ";
    }}
else if(num == 1)
{   cout<<"Numeros impares:"<<endl;
    for(impares=1; impares<=99; impares=impares+2)
    {   cout<<impares<<", ";
    }}
else if(num == 3)
{   cout<<"Numeros primos:"<<endl;
    cout<<"2, 3, 5, 7 ";
    for(primos=2; primos<=97; primos=primos+1)
    {
        if((primos%2 && primos%3 && primos%5 && primos%7)!=0)
        {
          cout<<primos<<", ";
        }}}

    return 0;
}

Compara dos números ingresados por el usuario

Programa que compara dos números ingresados por el usuario y verifica si son iguales
      o diferentes, desplegando un mensaje en pantalla correspondiente.

#include <iostream>

using namespace std;

float a, b;
int main()
{
    cout<<"Introduzca dos numeros aleatorios."<<endl;
    cout<<"Primer numero: ";
    cin>>a;
    cout<<"Segundo numero: ";
    cin>>b;

    if(a == b)
    {
        cout<<"Los numeros son iguales. "<<endl;
    }
        else if(a > b)
        {
            cout<<"El numero mayor es: ";
            cout<<a<<endl;
        }
        else if(a < b)
        {
            cout<<"El numero mayor es: ";
            cout<<b<<endl;
        }
    return(0);
}