UNIVERSIDAD MAYOR DE
SAN ANDRES
FACULTAD DE INGENIERIA
INGENIERIA ELECTRONICA
LABORATORIO Nº4
INFORME
PROGRAMACION
(ELTN-307)
DOCENTE: ING. JUAN CARLOS AVILES
CORTEZ
INTEGRANTES:
CABRERA MENDOZA MILTON
QUISBERT CRUZ ALVARO MICHEL
MARCA SANCHEZ RUBEN WILSON
PARALELO: “A”
GRUPO Nº: 16
FECHA: 11/04/2011
3.1 Escribir un programa que calcule y visualice el numero mayor, el menor y
la media de N números introducidos. El numero se solicitara al principio del
programa luego se introducirá la cantidad de números indicada puede
admitir números negativos, con decimales.
Inicio
Leer
n є Z+
S=0
i=1
i<=n PM=S/(i-1) Imp
PM,
May,men
Leer Fin
N
N≠0
i≠1
N≥May
May=N
Men=N
N≤men
May=N
men=N
S=S+N
i=i+1
CODIFICACON EN C++:
// Numero may, men, PM
#include <stdio.h>
#include <conio.h>
main()
{
int n, i;
float S,May, men, PM, N;
printf ("Leer n entero positivo: ");
scanf ("%d",&n);
S=0;
i=1;
while (i<=n)
{
printf ("Introdusca datos: ");
scanf ("%f",&N);
if (N!=0)
{
if (i==1)
{
May=N;
men=N;
}
else if (N>=May)
{
May=N;
}
else if (N<=men)
{
men=N;
}
S+=N;
i+=1;
}
}
PM=S/(i-1);
printf ("PM=%f\t May=%f\tmen=%f",PM,May,men);
getch();
}
SIMULACION:
Leer n entero positivo4
1. 2
2. 3 PM= 2 May= 4 men= -1
3. -1
4. 4
3.2 Escribir un programa que acepte un numero tipo entero y a continuación
los visualice como dicho numero en palabras. La entrada se termina con un
punto y coma.
CODIFICACION EN C++:
// convertir de numero a letra
#include <stdio.h>
#include <iostream.h>
void main()
{
int n,c,r,d,u; cout<<"introduce un numero entre 99 y 999: ";
cin>>n; cout<<endl;
c=n/100;
r=n%100;
d=r/10;
u=r%10;
switch (c)
{
case 1: if (d==0) cout<<"cien";
else cout<<"ciento"; break;
case 2: cout<<"docientos"; break;
case 3: cout<<"trecientos"; break;
case 4: cout<<"cuatrocientos"; break;
case 5: cout<<"quinientos"; break;
case 6: cout<<"seiscientos"; break;
case 7: cout<<"setecientos"; break;
case 8: cout<<"ochocientos"; break;
case 9: cout<<"novecientos"; break;
}
switch (d)
{
case 9: if (u==0) cout<<" noventa";
else cout<<" noventa y"; break;
case 8: if (u==0) cout<<" ochenta";
else cout<<" ochenta y"; break;
case 7: if (u==0) cout<<" setenta";
else cout<<" setenta y"; break;
case 6: if (u==0) cout<<" sesenta";
else cout<<" sesenta y"; break;
case 5: if (u==0) cout<<" cincuenta";
else cout<<" cincuenta y"; break;
case 4: if (u==0) cout<<" cuarenta";
else cout<<" cuarenta y"; break;
case 3: if (u==0) cout<<" treinta";
else cout<<" treinta y"; break;
case 2: if (u==0) cout<<" veinte";
else cout<<" veinti"; break;
case 1:
switch (u)
{
case 1: if(u==1) cout<<" once"; break;
case 2: if(u==2) cout<<" doce"; break;
case 3: if(u==3) cout<<" trece"; break;
case 4: if(u==4) cout<<" catorce"; break;
case 5: if(u==5)cout<<" quince"; break;
case 6: if(u==6)cout<<" dieciseis"; break;
case 7: if(u==7)cout<<" diecisiete"; break;
case 8: if(u==8)cout<<" dieciocho"; break;
case 9: if(u==9)cout<<" diecinueve"; break;
default: cout<<" diez"; break;
}
u = 0;
}
switch (u)
{
case 1: cout<<" uno"; break;
case 2: cout<<" dos"; break;
case 3: cout<<" tres"; break;
case 4: cout<<" cuatro"; break;
case 5: cout<<" cinco"; break;
case 6: cout<<" seis"; break;
case 7: cout<<" siete"; break;
case 8: cout<<" ocho"; break;
case 9: cout<<" nueve"; break;
}
[Link](); [Link]();
}
SIMULACION:
Leer un numero de 99-999225
Doscientos veinticinco