Está en la página 1de 10

ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

Ejercicio 1

Proceso primospromyfact
leer N
Dimension A[N]
Dimension Primos[N]
cont<-0
Para i<-0 Hasta N-1 Con Paso 1 Hacer
escribir "digite num"
leer A[i]
Para f<-1 Hasta N Con Paso 1 paso Hacer
si A[i]%f=0 Entonces
cont<-cont+1
FinSi
si cont=2 Entonces
A[N]<-Primos[N]
FinSi
Fin Para
Fin Para
Escribir " numeros primos"
Para i<-1 Hasta N Con Paso 1 Hacer
escribir Primos[i]
Fin Para
Escribir "sum y promedio"
Para i<-1 Hasta N Con Paso 1 Hacer
Sum<-A[i]+A[i]
prom<-sum/N
Fin Para
Escribir sum
Escribir prom
FinProceso
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

#include<iostream>
using namespace std;
#define ARREGLO_MAX 100
#define SIN_TIPO string
int main() {
float a[ARREGLO_MAX];
float cont;
float f;
int i;
int n;
SIN_TIPO primos[ARREGLO_MAX];
float prom;
float sum;
cin >> n;
cont = 0;
for (i=0;i<=n-1;i++) {
cout << "digite num" << endl;
cin >> a[i];
for (f=1;f<=n;f+=1 paso) {
if (a[i]%f==0) {
cont = cont+1;
}
if (cont==2) {
a[n] = primos[n];
}
}
}
cout << " numeros primos" << endl;
for (i=1;i<=n;i++) {
cout << primos[i] << endl;
}
cout << "sum y promedio" << endl;
for (i=1;i<=n;i++) {
sum = a[i]+a[i];
prom = sum/n;
}
cout << sum << endl;
cout << prom << endl;
return 0;
}
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

V2 cpp

#include <iostream>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
//definicion de variables
int NEL, I,J, contador=0 ;
int A[50], primos[50];
bool esprimo= true;
int sum; float prom=0;
long fact;
using namespace std;
void llenarvector();
void numprimos();
void factorial();

void MENU()
{
int OP;
do
{
//clrscr();
cout << " 1.- CAPTURA DATOS DE numeros \n";
cout << " 2.- PROVEDIO DEL VECTOR \n";
cout << " 3.- FACTORIAL DEL VECTOR A \n";

cout << " 4.- FIN NDEL PROCESO \n\n\n";


cout << " OPCION ?? >>> "; cin >> OP;

switch(OP)
{
case 1: llenarvector(); break;
case 2: numprimos(); break;
case 3: factorial(); break;

case 4: cout << " Pulse ENTER para terminar....."; getch();


break;

default: cout << " \n\n\n ERROR EN OPCION ... "; getch();
}
} while ( OP != 13);
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

//llenado del vector


void llenarvector(){

cout << " Cuantos numeros desea digitar? "; cin >> NEL;

if ( (NEL < 0) || (NEL > 50 ) ){


cout << " EL NUMERO MAXIMO DE ELEMENTOS ES 50 ";
getch();
}
else
{
for ( I=1; I<= NEL; I++)
{
cout << " Digite EL NUMERO "; cin >> A [I] ;

}
}
}

//almacenando numeros primos del vector A en el vector primos

void numprimos(){
//FOR PARA INDICAR CUANTOS NUMEROS PRIMOS HAY EN EL VECTOR
for(I=0; I=A[I]; I++){
esprimo=true;
//FOR PARA COMPROBAR QEU EL NUMERO ES PRIMO
for(J=2; J<I-1; J++){
if (I % J==0){
esprimo= false;
J=I;
}
}
if(esprimo==true){
contador=contador+1;

}
}

//inicializamos el vector primos con el numero que tenemos en el contador


int primos[contador];

//llenado del vector primos con los umeros primos del vector A
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

for(I=0; I<contador; I++){


esprimo=true;
for(J=2;J<A[I]-1;J++){
if(A[I] % J ==0 ){
esprimo=false;
}
}
if (esprimo==true){
primos[I]=A[I];
}
else{
I=I-1;
}
A[I]=A[I]+1;
}

//MOSTRANDO NUMEROS PRIMOS DEL VECTOR PRIMOS


cout<<"los numeros primos del vector A SON:\n ";
for(I=0; I<contador;I++){

cout<<primos[I]<<endl;
}
system("PAUSE");

void promedio(){

for(int i=0; i<NEL; i++){


sum=+ A[i];
prom=sum/NEL;
}
cout<<"el promedio del vector A ES " << prom;
}

//calcular factorial del vector A


void factorial(){

if (A[I]<0) {fact =0;}


else if (A[I]==0) {fact=1;}
else {
for (int i = 1; i <= A[I]; i++){
fact = fact*i;
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

}
}
cout<<" El Factorial de LOS ELEMENTOS DEL VECTOR A ES : " << fact << endl;

int main(){

MENU ();

}
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

Ejercicio 2

Pseudocodigo.

Algoritmo NotasP

Dimension Notas[20]
definir cd Como Entero
cd<-0
definir cr Como Entero
cr<-0
definir ca Como Entero
ca<-0
definir ce Como Entero
ce<-0
Para i<-0 Hasta 19 Con Paso 1 Hacer
Notas[i]<-Aleatorio(0,5)
Escribir Notas[i]
si (Notas[i]<=1)
cd<-cd+1
FinSi
si (Notas[i]>1&notas[i]<=3)
cr<-cr+1
FinSi
si (Notas[i]>3&notas[i]<=4)
ca<-ca+1
FinSi
si (Notas[i]>4&notas[i]<=5)
ce<-ce+1
FinSi
Fin Para
Escribir "los estudiantes con notas deficientes son:",cd
Escribir "los estudiantes con notas regulares son:",cr
Escribir "los estudiantes con notas buenos son:",ca
Escribir "los estudiantes con notas excelente son:",ce
FinAlgoritmo
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

CPP

#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
int ca;
int cd;
int ce;
int cr;
int i;
int notas[20];
cd = 0;
cr = 0;
ca = 0;
ce = 0;
for (i=0;i<=19;i++) {
notas[i] = (0+rand()%5--1);
cout << notas[i] << endl;
if ((notas[i]<=1)) {
cd = cd+1;
}
if ((notas[i]>1 && notas[i]<=3)) {
cr = cr+1;
}
if ((notas[i]>3 && notas[i]<=4)) {
ca = ca+1;
}
if ((notas[i]>4 && notas[i]<=5)) {
ce = ce+1;
}
}
cout << "los estudiantes con notas deficientes son:" << cd << endl;
cout << "los estudiantes con notas regulares son:" << cr << endl;
cout << "los estudiantes con notas buenos son:" << ca << endl;
cout << "los estudiantes con notas excelente son:" << ce << endl;
return 0;
}
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

Ejercicio 3
Pseudocodigo
Proceso Sumavectores
escribir "digite el tamaño de los vectores a y b"
leer N
dimension A[N]
dimension B[N]
Dimension C[N]
Dimension D[N]
Dimension E[N]
Escribir "Guardar datos......"
Para i<-0 Hasta N-1 Con Paso 1 Hacer
escribir"datos vec a",i
leer A[i]
Fin Para
Para i<-0 Hasta N-1 Con Paso 1 Hacer
Escribir "datos vec b",i
leer B[i]
Fin Para
escribir "1. sumar vector A + vector B"
Para i<-0 Hasta N-1 Con Paso 1 Hacer
C[i]<-A[i]+B[i]
Escribir "posicion # ",i "=",C[i]
Fin Para
Escribir "2. almacenar vector a y b en un solo vector"
Para i<-0 Hasta N-1 Con Paso 1 Hacer
D[i]<-A[i]
Escribir D[i]
D[i]<-B[i]
Escribir D[i]
Fin Para

Escribir "3.vector inv de a"


Para i<-1 Hasta N Con Paso 1 Hacer
Escribir A[N]
Fin Para

FinProceso
ROBERTO CARLOS GARCIA GONZALEZ ESTRUCTURA DE DATOS

CPP

#include<iostream>
using namespace std;
#define ARREGLO_MAX 100
#define SIN_TIPO string
int main() {
SIN_TIPO a[ARREGLO_MAX];
SIN_TIPO b[ARREGLO_MAX];
SIN_TIPO c[ARREGLO_MAX];
SIN_TIPO d[ARREGLO_MAX];
SIN_TIPO e[ARREGLO_MAX];
int i;
int n;
cout << "digite el tamaño de los vectores a y b" << endl;
cin >> n;
cout << "Guardar datos......" << endl;
for (i=0;i<=n-1;i++) {
cout << "datos vec a" << i << endl;
cin >> a[i];
}
for (i=0;i<=n-1;i++) {
cout << "datos vec b" << i << endl;
cin >> b[i];
}
cout << "1. sumar vector A + vector B" << endl;
for (i=0;i<=n-1;i++) {
c[i] = a[i]+b[i];
cout << "posicion # " << i << "=" << c[i] << endl;
}
cout << "2. almacenar vector a y b en un solo vector" << endl;
for (i=0;i<=n-1;i++) {
d[i] = a[i];
cout << d[i] << endl;
d[i] = b[i];
cout << d[i] << endl;
}
cout << "3.vector inv de a" << endl;
for (i=1;i<=n;i++) {
cout << a[n] << endl;
}
return 0;
}

También podría gustarte