top of page
consola de programación

clase perteneciente a la practica califica numero 03:

EJERCICIOS PRACTICADOS EN CLASE:

# include <iostream>
# include <math.h>
# include <stdio.h>
# include <conio.h>
using namespace std;
int opcion=0, n=0 , c=0, i=0, j=0, base, fact; 
int bisiesto(int);
float POTENCIA(int x, double y), SERIE(int z);
float A, B, D, exponente, SUMA;
float f(float q);
float f(float x) {
    return 2 * M_PI * tan(x) * sqrt(1 + pow(1 / cos(x), 4));
}
float ancho(float a, float b, int n) {
    return (b - a) / n;
}
int main(){
do{
cout << "    MENU DE FUNCIONES "<< endl;
cout << " ----------------------------"<< endl;
cout << "  [1] POTENCIA"<< endl;
cout << "  [2] SERIE"<< endl;
cout << "  [3] BISIESTO"<< endl;
cout << "  [4] INTEGRAL DEFINIDA"<< endl;
cout << "\n  INGRESE UNA OPCION <> 0 : "; cin>>opcion;
cout << " ----------------------------"<< endl;
switch (opcion){
   case 1:{
       cout << "  [1] POTENCIA"<< endl;
       cout << " ----------------------------"<< endl;
       cout << "Ingrese el valor de la Base: "; cin>>base;
       cout << "Ingrese el valor del Exponente: ";cin>>exponente;
           POTENCIA(base, exponente); //INVOCACION
           cout<<"Resultado: "<<POTENCIA(base, exponente)<<endl;
           cout << " ----------------------------"<< endl;
       break;
   }
   case 2:{
       cout << "  [2] SERIE"<< endl;
       cout << " ----------------------------"<< endl;
       cout << "Ingrese el numero: "; cin>>n;
       D = SERIE(n);
       cout<<"Resultado: "<<D;
       cout << "\n ----------------------------"<< endl;
       break;
   }
   case 3:{
       cout << "  [3] BISIESTO"<< endl;
       cout << " ----------------------------"<< endl;
   int anio;
   cout<<"Introduce a"<<(char)164<<"o: "; //164 ascii de ñ
   cin >> anio;
   if(bisiesto(anio))  //llamada a la función
      cout << "Bisiesto" << endl;
   else
      cout << "No es bisiesto" << endl;
      cout << " ----------------------------"<< endl;
       break;
   }
   case 4:{
       cout << "  [4] INTEGRAL DEFINADA"<< endl;
       cout << " ----------------------------"<< endl;
   float a = 0; // Límite inferior
    float b = M_PI / 4; // Límite superior
    int n = 1000; // Número de trapecios
    float h = ancho(a, b, n);
    float sum = 0;

    // Evaluar en el límite inferior
    sum = f(a);

    // Evaluar f(xi) para i = 1, 2, ..., n-1
    for (int i = 1; i <= n - 1; ++i) {
        sum += 2 * f(a + h * i);
    }

    // Evaluar en el límite superior
    sum += f(b);

    // Calcular la integral
    float integral = h * sum / 2;

    cout << "El resultado de la integral es: " << integral;
       break;
   }
       
}    
} while (opcion!=0);    
}

float POTENCIA(int x, double y){
   A = pow(x, y);
   return A;
}

float SERIE(int z){
   fact=1;
   SUMA=0;
   for(c=1; c<=z; c++){
       fact=fact*c;
       B = 2 + pow(c,c);
       SUMA = SUMA + fact/B;
   }
   return (SUMA);
}

int bisiesto(int a)   //definición de la función    
{
    if(a%4==0 and a%100!=0 or a%400==0)
        return 1;
    else
        return 0;
}

bottom of page