#include <stdio.h>#define PI 3.141592654float areaCirculo( float radio );int main (void){ float radio=0.0; //DECLARACIÓN E INTIALIZACIÓN DE LA VARIABLE //PEDIR VALOR printf("Radio del circulo: "); scanf("%f",&radio); //CALCULO, LLAMAR FUNCION areaCirculo Y MOSTRARLA DIRECTAMENTE //AHORRA MEMORIA printf("El area del circulo es: %.2f\n",areaCirculo(radio)); return 0;}float areaCirculo( float radio ){ float area = 0.0; //VARIABLE PARA AREA area = PI*(radio*radio); //FORMULA return area;}
#include <stdio.h>float converToKelvin( float centigrado );int main(void){ float centigrado=0.0, kelvin=0.0; // VARIABLE PARA ALMACENAR CENTIGRADOS Y SU CONVERSIÓN A GRADOS KELVIN //PEDIR VALOR EN CENTIGRADOS printf("Introduzca temperatura en centigrados: "); scanf("%f",¢igrado); //LLAMAR FUNCION QUE CONVIERTE DE CENTI A KELVIN kelvin = converToKelvin(centigrado); //MOSTRAR RESULTADO printf("Resultado:\n%.2f grados °C = %.2f grados °K\n",centigrado,kelvin);}float converToKelvin( float centigrado){ float k=273.15; k = (centigrado+k); //FORMULA KELVIN return k;}
#include <stdio.h>int main ( void ){ int lanzamiento=0,dado1=0,dado2=0,suma=0; int array[12]; for ( lanzamiento = 0; lanzamiento < 11; lanzamiento++ ){ array[lanzamiento]=0; } for ( lanzamiento = 0; lanzamiento < 36000; lanzamiento++ ){ //REALIZAR 36000 VECES //LANZAMOS LOS DADOS dado1 = (rand()%6+1); dado2 = (rand()%6+1); suma = dado1+dado2; //CONTROL DE SUMANDOS //PARA CADA OCURRENCIA switch (suma){ case 2: array[0]+=1; break; //EN CASO DE QUE SALGA UN DOS case 3: array[1]+=1; break; //EN CASO DE QUE SALGA UN TRES case 4: array[2]+=1; break; //EN CASO DE QUE SALGA UN CUATRO case 5: array[3]+=1; break; //EN CASO DE QUE SALGA UN CINCO case 6: array[4]+=1; break; //EN CASO DE QUE SALGA UN SEIS case 7: array[5]+=1; break; //EN CASO DE QUE SALGA UN SIETE case 8: array[6]+=1; break; //EN CASO DE QUE SALGA UN OCHO case 9: array[7]+=1; break; //EN CASO DE QUE SALGA UN NUEVE case 10: array[8]+=1; break; //EN CASO DE QUE SALGA UN DIEZ case 11: array[9]+=1; break; //EN CASO DE QUE SALGA UN ONCE case 12: array[10]+=1; break;//EN CASO DE QUE SALGA UN DOSCE default: puts("Error!"); break; //SI TODO FALLA } printf("%8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d|\n",array[0],array[1],array[2],array[3],array[4],array[5],array[6],array[7],array[8],array[9],array[10]); } //MOSTRAR RESULTADOS puts("\n\nTOTAL DE LANZAMIENTOS-------------------\n"); //TABLA DE VALORES CON EL NUMERO DE LOS DADOS printf("\nN°: %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| ",2,3,4,5,6,7,8,9,10,11,12); //CANTIDAD DE APARICIONES DE CADAD VALOR printf("\nOc: %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| %8d| ",\ array[0],array[1],array[2],array[3],array[4],array[5],array[6],array[7],array[8],array[9],array[10]); //PORCENTAJE DE CADA OCURRENCÍA printf("\nP%:\t%4.1f %8.1f %10.1f %10.1f %8.1f %10.1f %8.1f %10.1f %8.1f| %8.1f %10.1f ",\ ((float)array[0]*100/36000),((float)array[1]*100/36000),((float)array[2]*100/36000),((float)array[3]*100/36000),((float)array[4]*100/36000),((float)array[5]*100/36000),((float)array[6]*100/36000),\ ((float)array[7]*100/36000),((float)array[8]*100/36000),((float)array[9]*100/36000),((float)array[10]*100/36000)); puts("\n\n36000 lanzamientos efectuados\nNúmero de veces para ocurrencía de valores"); puts("\n"); return 0;}
#include <stdio.h>#include <math.h> //PARA sqrt() (CALCULO DE RAICES9float x1 ( float a, float b, float c ); //FUNCIÓN PARA EL RESULTADO 1float x2 ( float a, float b, float c ); //FUNCIÓN PARA EL RESULTADO 2int main ( void ){ float a=0.0,b=0.0,c=0.0; //COEFICIENTES DE LAS VARIABLES float resul1=0.0,resul2=0.0; //RESULTADO DE LAS DOS RAICES printf("Introduzca a: "); scanf("%f",&a); printf("Introduzca b: "); scanf("%f",&b); printf("Introduzca c: "); scanf("%f",&c); if ( a == 0.0){ // a NO PUEDE VALER 0, CAUSARIA UNA DIVISIÓN POR 0, "funcion no definida" puts("Error matematico! Division por 0, a = 0!"); puts("La ecuación no tiene solucion"); return 0; } else{ resul1 = x1(a,b,c); //LLAMA A LAS FUNCIONES PARA CALCULAR LAS RAICES resul2 = x2(a,b,c); } //MOSTRAR RESULTADOS puts("Resultados: "); printf("Resultado, primera raiz: %.2f\n",resul1); printf("Resultado, segunda raiz: %.2f\n",resul2); return 0;}float x1 ( float a, float b, float c){ float resultado =0.0; resultado = ((b*b)-(4*a*c)); //COMPRUEBA SI LA RAIZ ES NEGATIVA if ( resultado < 0 ){ puts("Raiz uno negativa, ecuación sin solución"); //EN CASO DE SER NEGATIVA MUESTRA ESTE MENSAJE } resultado = ((-b)+sqrt(resultado)); resultado /= (2*a); return resultado;}float x2 ( float a, float b, float c){ float resultado =0.0; resultado = ((b*b)-(4*a*c)); //COMPRUEBA SI LA RAIZ ES NEGATIVA if ( resultado < 0 ){ puts("Raiz dos negativa, ecuación sin solución"); //EN CASO DE SER NEGATIVA MUESTRA ESTE MENSAJE } resultado = ((b)+sqrt(resultado)); resultado /= (2*a); return resultado;}
#include <stdio.h> //PARA PRINTF Y SCANFint factorial(int n);int main(void){ double ecuacion1=0.0,ecuacion2=0.0,ecuacion3=0.0; int x=0; //PEDIR VALOR DE "x" printf("Introduzca x: "); scanf("%d",&x); //DEFINIR ECUACIÓN Y GUARDAR RESULTADO EN LA VARIABLE "ecuación" ecuacion1 = (1.0/factorial(x)); printf("Ecuacion 1: %f\n",ecuacion1); ecuacion2 = (1.0/factorial(x-2)); printf("Ecuacion 2: %f\n",ecuacion2); ecuacion3 = (1.0/factorial(x-3)); printf("Ecuacion 3: %f\n",ecuacion3); //MOSTRAR RESULTADO printf("El resultado de la ecuación es: %.2f\n",(ecuacion1+ecuacion2+ecuacion3)); return 0;}int factorial( int n ){ //DECLARACIÓN E INTIALIZACIÓN DE VARIABLEA int fact = n; //RETORNAR DIRECTAMENTE EL VALOR SI SE INTRODUCE 2 if ( fact == 2){ return fact; } else if ( fact == 0){ return 1; } else if ( fact == 1 || fact == -1 ){ return fact; } //REALIZAR FACTORIAL HASTA QUE b SEA IGUAL A 1 else { fact = fact * factorial(fact-1); return fact; }}
#include <math.h>#include <stdio.h>#define euler 2.718281828int main(void){ int potencia = 0; //PEDIR POTENTICA printf("Introduzca potencia: "); scanf("%d",&potencia); //CONTROL DE POTENCIAL, NO PUEDE SER NEGATIVA if (potencia < 0){ puts("Error! Potencia negativa"); return 0; } //ELEVAR E A LA POTENCIA Y MOSTRAR DIRECTAMENTE printf("Resultado: %.5f\n",pow(euler,potencia)); return 0;}
#include <stdio.h> //PARA PRINTF Y SCANFint factorial(int n);int main(void){ //DECLARACIÓN DE VARIABLES int n,resultado; //PEDIR VALOR DE n puts("Introduzca el valor de n: "); scanf("%d", &n); //LLAMAR A LA FUNCIÓN resultado = factorial(n); //MOSTRAMOS EL RESULTADO printf("El resultado es: %d\n",resultado); return 0; }int factorial( int n ){ //DECLARACIÓN E INTIALIZACIÓN DE VARIABLEA int fact = n; //RETORNAR DIRECTAMENTE EL VALOR SI SE INTRODUCE 2 if ( fact == 2){ return fact; } //REALIZAR FACTORIAL HASTA QUE b SEA IGUAL A 1 else { fact = fact * factorial(fact-1); return fact; }}
#include <stdio.h> // para printf(), scanf() y puts()float kelvinToCelsius( float kelvin ); // CONVERTIR PRIMERO LA LECTURA A CELCIUSfloat celsiusToFahrenheit( float celsius ); // LUEGO CONVERTIR A FAHRENHEITint main(void){ float kelvin=0.0, celsius=0.0, fahrenheit=0.0; //VARIABLES DE DENOMINACIÓN PARA GUARDAR DATOS //PEDIR VALORES DE ENTRADA printf("Introduzca los grados kelvin (°K): "); scanf("%f", &kelvin); //LLAMAR A LA FUNCIÓN PARA CONVERTIR A CENTIGRADOS Y EL RESULTADO GUARDARLO EN LA VARIABLE "celsius" celsius = kelvinToCelsius(kelvin); //LLAMAR A LA FUNCIÓN PARA CONVERTIR A FAHRENHEIT fahrenheit = celsiusToFahrenheit(celsius); //MOSTRAR RESULTADO printf("Resultado:\n%.2f grados °K = %.2f grados °F\n",kelvin,fahrenheit); return 0;} float kelvinToCelsius ( float kelvin ){ float celsius=0.0; celsius = (kelvin - 273.15); //CONVERSIÓN DE KELVIN A CELSIUS return celsius;}float celsiusToFahrenheit ( float celsius ){ float fahrenheit=0.0; fahrenheit = ((1.8)*celsius+32.0); //CONVERSION A FAHRENHEIT, EN EL ENUNCIADO ESTA MAL, FORMULA = (1.8)*°c+32 return fahrenheit;}
#include <stdio.h>#include <math.h>int main(){ double numero, resultado; printf("\nIntroduce valor: "); scanf("%lf", &numero); if (numero > 0) { resultado = log10(numero); printf("\nEl logaritmo de %.3f es %.3f", numero, resultado); } return 0;}
#include <stdio.h>#include <math.h>int main ( void ){ double x=0.0,resultado=0.0; puts("Calculo de logaritmos"); do { printf("Introduzca numero a calcular:"); scanf("%lf",&x); //CONTROL if ( x < 0.0){ puts("Error matematico! No se admiten numeros negativos"); } else{ resultado =log10(x); break; } }while ( x < 0 ); printf("Logaritmo de %.2f = %.5f\n", x, resultado); return 0; }
#include <stdio.h>unsigned int elevar( unsigned int numero, unsigned int potencia );int main( void ){ unsigned int n=0,p=0,resultado=0; //VALORES INICIALES DE LAS VARIABLES n(NUMERO), p(POTENCIA) //PEDIR VALORES printf("Numero a elevar: "); scanf("%d",&n); printf("Potencia: "); scanf("%d",&p); //LLAMAR FUNCIÓN elevar() Y SUS REGRESO GUARDARLO EN LA VARIABLE RESULTADO resultado = elevar(n,p); //MOSTRAR RESULTADO printf("N: %d elevado a P: %d = %d\n",n,p,resultado); return 0;} unsigned int elevar ( unsigned int numero, unsigned int potencia){ unsigned int constante = numero; // BASE A MULTIPLICAR //EL CICLO SE REPETIRA HASTA QUE potencia se igual a uno while ( potencia > 1){ numero *= constante; //MULTIPLICAR numero por si mismo potencia--; //RESTAR POTENCIA EN FACTOR DE 1 } return numero;}
#include <stdio.h>int main( void ){ int matriz1[10][10],matriz2[10][10], matrizRes[10][10],i=0,j=0,n=0; printf("Tamanho de matrices: "); scanf("%d",&n); puts("Introducir valores para la matriz 1: "); printf("\t\t---------------------------------- \n"); for( i=0; i < n; i++ ){ for( j=0; j < n; j++ ){ printf("A(%d,%d) = ",i,j); scanf("%d",&matriz1[i][j]); } } puts("Introducir valores para la matriz 2: "); printf("\t\t---------------------------------- \n"); for( i=0; i < n; i++ ){ for( j=0; j < n; j++ ){ printf("A(%d,%d) = ",i,j); scanf("%d",&matriz2[i][j]); } } //MULTIPLICAR INDIVIDUALMENTE Y GUARDAR EL "matrizRes" puts("Resultado:"); for( i=0; i < n; i++ ){ for( j=0; j < n; j++ ){ matrizRes[i][j]=matriz1[i][j]*matriz2[i][j]; printf("%5d|",matrizRes[i][j]); } printf("\n"); } return 0; }