Apuntes de Microcontroladores

miércoles, 9 de diciembre de 2020

Cálculo de Ley De Ohm (Switch) y Do - While.

 /* ÁNGEl COZAR RAMOS - CALCULO DE LEY DE OHM USANDO SWITCH Y DO-WHILE*/

#include <stdio.h>         

#include <math.h>


int main()

{

float I, V, R; /*DECLARAMOS LASS VARIABES QUE VAMOS A UTILIZAR*/

int seleccion; /*vARIABLE DEL A UTILIZAR EN EL SWICHT*/

    char repetir_variable ;

do {

printf("\n\t CALCULADORA DE LA LEY DE OHM \n\n"); /*INTRODUCCIÓN*/

printf(" Introduzca el numero de la magnitud a calcular:\n\n"); /*PETICIÓN POR PANTALLA*/

printf("   1 - Intensidad \n"); /*PETICIÓN POR PANTALLA*/

printf("   2 - Resistencia \n"); /*PETICIÓN POR PANTALLA*/

printf("   3 - Tension \n"); /*PETICIÓN POR PANTALLA*/

scanf("%d", &seleccion); /*INTRODUCCIÓN DE LA PETICIÓN*/

switch(seleccion)

{

case 1:

do {

  printf("\t CALCULO DE LA INTENSIDAD \n\n"); /*VISUALIZACION DE LA OPERACION A REALIZAR*/

          printf("Introduzca el valor de la Tension (V): ");  /*VISUALIZACION Y PETICION DE LOS VALORES*/

          scanf("%f", &V); /*INTRODUCCION DEL VALOR DESEADO*/

          printf("Introduzca el valor de la Resistencia (R): ");  /*VISUALIZACION Y PETICION DE LOS VALORES*/

          scanf("%f", &R); /*INTRODUCCION DEL VALOR DESEADO*/

          I = V / R ; /*OPERACION A REALIZAR */

              printf("\nEl calculo de %.2f Voltios y %.2f Ohmios es %.2f Amperios", V, R, I); /*VISUALIZACION DEL RESULTADO OBTENIDO*/

            

  printf("\n\n ¿Desea repetir el calculo de esta variable? Pulsa s (Si) y otra tecla distinta (No):");

  scanf(" %c", &repetir_variable);

  

   }

   

            while(repetir_variable == 's');

            

break;

           

   

    case 2:

    do {

 

    printf("\t CALCULO DE LA RESISTENCIA \n\n"); /*VISUALIZACION DE LA OPERACION A REALIZAR*/

             printf("Introduzca el valor de la Tension (V): ");  /*VISUALIZACION Y PETICION DE LOS VALORES*/

         scanf("%f", &V); /*INTRODUCCION DEL VALOR DESEADO*/

         printf("Introduzca el valor de la Intensidad (I): ");  /*VISUALIZACION Y PETICION DE LOS VALORES*/

         scanf("%f", &I); /*INTRODUCCION DEL VALOR DESEADO*/

         R = V / I ; /*OPERACION A REALIZAR */

         printf("\nEl calculo de %.2f Voltios y %.2f Amperios es %.2f Ohmios", V, I, R); /*VISUALIZACION DEL RESULTADO OBTENIDO*/

         

         printf("\n\n ¿Desea repetir el calculo de esta variable? Pulsa s (Si) y otra tecla distinta (No):");

scanf(" %c", &repetir_variable);

  

   }

   

            while(repetir_variable == 's');

    break;

   

    case 3:

   

    do {

    printf("\t CALCULO DE LA TENSION \n\n"); /*VISUALIZACION DE LA OPERACION A REALIZAR*/

        printf("Introduzca el valor de la Resistencia (R): ");  /*VISUALIZACION Y PETICION DE LOS VALORES*/

        scanf("%f", &R); /*INTRODUCCION DEL VALOR DESEADO*/

        printf("Introduzca el valor de la Intensidad (I): ");  /*VISUALIZACION Y PETICION DE LOS VALORES*/

        scanf("%f", &I); /*INTRODUCCION DEL VALOR DESEADO*/

        V = I * R ; /*OPERACION A REALIZAR */

        printf("\nEl calculo de %.2f Ohmios y %.2f Amperios es %2.f Voltios", R, I, V); /*VISUALIZACION DEL RESULTADO OBTENIDO*/

        

        printf("\n\n ¿Desea repetir el calculo de esta variable? Pulsa s (Si) y otra tecla distinta (No):");

  scanf(" %c", &repetir_variable);

  

   }

   

            while(repetir_variable == 's');     

    break;   

    default:

printf("\nEl numero marcado no coincide con ninguna magnitud"); /*MUESTRA EN PANTALLA UN FALLO NUMERICO*/

    }

}

         printf("\n\n ¿Volver al menu principal? Pulse s (Si) y otra tecla distinta (No):");

      scanf(" %c", &repetir_variable);   

   }   

            while(repetir_variable == 's');

}

No hay comentarios:

Publicar un comentario