MAYO 1 PROYECTO día de la madre el amor más grande
Funciones con retorno en lengaje c utp ejemplos
1. 07/26/2015 profesor: E Batista Him 128
EJEMPLO DE FUNCION CON RETORNO APLICADA
A CONCEPTOS DE LA FISICA
PODEMOS CONFECIONAR UNA
FUNCION EN LENGUEAJE DE
PROGRAMACION C, CON
RETORNO, PARA CALCULAR EL
TIEMPO DE CAIDA LIBRE DEL
PROBLEMA ANTERIOR
2. 07/26/2015 profesor: E Batista Him 129
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <string.h>
fx_caidalibre(float h, float g); /*Declaracion de la funcion*/
//*ejempo de llamado a una funcion: fx_caida libre
main() {
int r;
float g=9.8 ,h, t;
printf ("Universidad Tecnológica de Panamán");
printf ("Facultad de Ingeniería Eléctrica n");
printf("Ingrese el La altura de H:n");
scanf("%f", &h);
r=fx_caidalibre( h,g);
printf("El tiempo de caida es t, main= %.2f n", r/1000.);
printf("Ingrese otra altura de H:n");
scanf("%f", &h);
r=fx_caidalibre( h,g);
printf("El otro tiempo caida es t main= %.2f n", r/1000.);
}
fx_caidalibre(float h, float g) // la función caída libre
{
float tt; /*Declaracion de las variables locales*/
if(h<0) {
printf("La altura en negativa n");
tt=0; }
else {
tt= sqrt(2*h/g);
return tt*1000 ; // convertimos a enteros
}
}
EJEMPLO DE FUNCION CON RETORNO : CAIDA LIBRE EN FISICA
3. 07/26/2015 profesor: E Batista Him 130
RESULTADO DEL PROGRAMA, LLAMANDO A UNA FUNCION CON
RETORNO
4. 07/26/2015 profesor: E Batista Him 131
OTRO EJEMPLO DE FUNCION CON RETORNO APLICADA
A CONCEPTOS DE LA FISICA, EN PROYECTILES
PODEMOS CONFECIONAR UNA
FUNCION EN LENGUEAJE DE
PROGRAMACION C, CON RETORNO,
PARA CALCULAR EL TIEMPO TOTAL
DE VUELO, EL TIEMPO DE SUBIDA Y
LA ALTURA MAXIMA ALCANZADA
5. 07/26/2015 profesor: E Batista Him 132
EJEMPLO DE FUNCION CON RETORNO : PROYECTILES EN FISICA
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <string.h>
#define PI 3.14159265
fx_proyectil(float vi, float g, float angulo); /*Declaracion de la funcion*/
//*ejempo de llamado a una funcion: fx_proyectil
main() {
float g=9.8,ymax, t_vuelo,t_subida,vi, angulo;
int t_v;
printf ("Universidad Tecnológica de Panamán");
printf ("Facultad de Ingeniería n");
printf("Ingrese la Velocidad inicial vi:n");
scanf("%f", &vi);
printf("Ingrese el angulo en grados :n");
scanf("%f", &angulo);
t_v = fx_proyectil( vi, g, angulo);
t_vuelo= t_v/100.0; // convertimos a decimales
t_subida= t_vuelo/2.0; // formula y = v0* sen(x)*t -1/2gt*t
ymax = vi*sin(angulo/180*PI)*t_subida - (0.5)*g*t_subida*t_subida;
printf("El tiempo de vuelo tv, main= %.2f n", t_vuelo );
printf("El tiempo de subida ts, main= %.2f n", t_subida );
printf("La maxima alura es ymax main= %.2f n", ymax );
return 0;
}
// funcion proyectil
fx_proyectil(float vi, float g, float angulo) {
float tv ;
tv= (2*vi)*sin(angulo/180*PI)/g;
return tv*100 ; // convertimos a enteros
}
6. 07/26/2015 profesor: E Batista Him 133
RESULTADO DEL PROGRAMA, LLAMANDO A UNA FUNCION CON
RETORNO
// funcion proyectil
fx_proyectil(float vi, float g, float
angulo) {
float tv ;
tv= (2*vi)*sin(angulo/180*PI)/g;
return tv*100 ; // convertimos a enteros
}