Академический Документы
Профессиональный Документы
Культура Документы
#include"stdafx.h"
#include<iostream>
#include<conio.h>
#include<math.h>
#include<time.h>
using namespace std;
Menu
do{
cout<<"Elija una opcion\n";
cout<<"1. cosa 1\n";
cout<<"2. cosa 2\n";
cout<<"3. cosa 3\n";
cout<<"4. cosa 4\n";
cin>>n;
switch(n){
case 1: cout<<"cosa 1"; break;
case 2: cout<<"cosa 2";break;
case 3: cout<<"cosa 3";break;
case 4: cout<<"cosa 4";break;
default: r=5;}}while(r==5);
}while(r==1);
Numero mayor
M=n;
if(p>M)
M=p;
if(q>M)
M=q;
if(r>M)
M=r;
if(s>M)
M=s;
for(i=1;i<=n;i++)
{p=2*i;
cout<<"Numero par: "<<p<<"\n";};
factorial de un numero
long f=1;
for ( int c=1; c<=n; c++)
f *=c;
return f;
FUNCIONES
/*2.- Desarrolle un programa que implemente dos funciones: una que retorne el mayor
de dos nmeros reales y
otra que retorne el mayor de 3 nmeros reales utilizando la primera funcin.
Ingrese tres nmeros y determine el mayor entre la combinacin de ellos.*/
#include"stdafx.h"
#include<iostream>
#include<conio.h>
int mayor2(int a, int b);//van declarados los parametro y la function con int o voi
void main()
{int a,b,c,M,m;
cout<<"Ingrese tres numeros\n";cin>>a>>b>>c;
M=mayor2(a,b);m=mayor2(M,c);//solo se usa la funcon no se declara nada
cout<<"El mayor de los tres numeros es "<<M;_getch();
}
void llenarvector(){
srand(time(NULL));
for(int i=0;i<10numero de elementos del vector;i++)
c[i]=aleatorio(100,999);
#include"stdafx.h"
#include<iostream>
#include<conio.h>
#include<math.h>
#include<time.h>
using namespace std;
# define FIL 15
# define COL 5
int c[FIL][COL];
void llenarmatriz();
int aleatorio(int a, int b);
void lista();
void main(){
llenarmatriz();
lista();_getch();
void llenarmatriz(){
srand(time(NULL));
for(int j=0;j<COL;j++){
for(int i=0;i<FIL;i++)
c[i][j]=aleatorio(100,999);}
PARA MATRICES
#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;
// declaraciones globales
#define FIL 15
#define COL 5
int m[FIL][COL];char* l[FIL][COL];
// prototipos
int menu();
void opcion1();
void opcion2();
void opcion3();
void opcion4();
void mostrar();
void mostrar2();
int aleatorio(int vmin, int vmax);
void ordena(int v[], int n);
void main()
{ int op;
do{
op=menu();
switch(op){
case 1: opcion1(); break;
case 2: opcion2(); break;
case 3: opcion3(); break;
case 4: opcion4(); break;
}
}while(op!=0);
}
// desarrollo de prototipos
int menu(){
int op;
cout<<"MENU DE OPCIONES"<<endl;
cout<<"[1] Genera y muestra"<<endl;
cout<<"[2] Diagrama"<<endl;
cout<<"[3] Nueva matriz"<<endl;
cout<<"[4] Ordena"<<endl;
cout<<"[0] Fin"<<endl;
cout<<"OPCION: "; cin>>op;
return op;
}
void opcion1(){srand(time(NULL));
cout<<"Generando numeros aleatorios..."<<endl;
for(int f=0; f<FIL; f++)
for( int c=0; c<COL; c++)
m[f][c] = aleatorio(0,9);
mostrar();
}
void opcion2(){int p;
for(int n=0;n<10;n++)
{p=0;
for(int i=0;i<FIL;i++)
{for(int j=0;j<COL;j++)
{if(m[i][j]==n)
p++;}}cout<<n;for(int h=0;h<p;h++)
cout<<"*";
cout<<p<<" ocurrencias\n";}
}
void mostrar(){
cout<<"CONTENIDO DE LA MATRIZ"<<endl;
for(int f=0; f<FIL; f++){
for(int c=0; c<COL; c++)
cout<<m[f][c]<<"\t";
cout<<endl;
}}
void mostrar2(){
cout<<"CONTENIDO DE LA MATRIZ"<<endl;
for(int f=0; f<FIL; f++){
for(int c=0; c<COL; c++)
cout<<l[f][c]<<"\t";
cout<<endl;
}}
}mostrar2();
}
}
}
}
}mostrar();}
void opcion2(){int f;
cout<<"Introduzca la fila a ordenar ";cin>>f;
for(int c=0;c<COL;c++){
for(int x=0;x<COL;x++){
if(m[f-1][c]>m[f-1][x]){
int aux=m[f-1][c];
m[f-1][c]=m[f-1][x];
m[f-1][x]=aux;
}}}
mostrar();
}
void opcion3(){int f;
for(int f=0;f<COL;f++)
{for(int c=0;c<COL;c++){
for(int x=0;x<COL;x++){
if(m[f-1][c]>m[f-1][x]){
int aux=m[f-1][c];
m[f-1][c]=m[f-1][x];
m[f-1][x]=aux;
}}}}
mostrar();
}
PRIMERO
#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;
// declaraciones globales
#define FIL 7
#define COL 10
int m[FIL][COL];
// prototipos
int menu();
void opcion1();
void opcion2();
void mostrar();
int aleatorio(int vmin, int vmax);
void main()
{ int op;
do{
op=menu();
switch(op){
case 1: opcion1(); break;
}
}while(op!=0);
}
// desarrollo de prototipos
int menu(){
int op;
cout<<"MENU DE OPCIONES"<<endl;
cout<<"[1] Genera y muestra"<<endl;
cout<<"[2] Diagrama"<<endl;
cout<<"[3] Nueva matriz"<<endl;
cout<<"[4] Ordena"<<endl;
cout<<"[0] Fin"<<endl;
cout<<"OPCION: "; cin>>op;
return op;
}
void opcion1(){srand(time(NULL));
cout<<"Generando numeros aleatorios..."<<endl;
for(int f=0; f<FIL; f++)
for( int c=0; c<COL; c++)
m[f][c] = aleatorio(0,9);
mostrar();
}
void mostrar(){
cout<<"CONTENIDO DE LA MATRIZ"<<endl;
for(int f=0; f<FIL; f++){
for(int c=0; c<COL; c++)
cout<<m[f][c]<<"\t";
cout<<endl;
}}
int aleatorio(int vmin, int vmax){
return rand()%(vmax-vmin+1)+vmin;
}