Está en la página 1de 4

/ prog012.cpp: define el punto de entrada de la aplicacin de consola. //Lazo repetitivo //Leer un numero //e imprimir el numero //al reves.

lee 2371 e imprime 1732 #include "stdafx.h" #include"iostream" #include"conio.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) {int num; int numinv; int digito; cout <<"Ingrese un numero=>"; cin>>num; numinv = 0; while(num>0) {digito= num%10; numinv = numinv*10 + digito; num = num/10; } cout<<"numero invertido =>"<<numinv; -getch(); return 0;

/ prog022.cpp: define el punto de entrada de la aplicacin de consola. //funciones #include "stdafx.h" #include"iostream" #include"conio.h" using namespace std; int suma(int a,int b) ; // prototipo de suma int _tmain(int argc, _TCHAR* argv[]) {int v1,v2; int s; cout<<"ingrese valor 1=>"; cin>>v1; cout<<"ingrese valor 2=>"; cin>>v2; s=suma(v1,v2);//invocacion de la funcion suma cout<<"suma="<<s; -getch(); return 0; } int suma(int a , int b) {return(a+b);}

// prog032.cpp: define el punto de entrada de la aplicacin de consola. //funciones #include "stdafx.h" #include "iostream" #include "conio.h" using namespace std; void leer(int *p1,int *p2); //llamada por referencia int sumar(int a, int b) ; //llamada por valor void escribir(int x); //llamada por valor int _tmain(int argc, _TCHAR* argv[]) {int v1,v2; int s; leer(&v1,&v2); s=sumar(v1,v2); cout<<"suma = "; escribir (s); return 0; } void leer(int *p1,int *p2) {cout<<"ingrese 1er valor=>"; cin>>(*p1); cout<<"ingrese 2dp valor=>"; cin>>(*p2); } int sumar(int a, int b) {int suma; suma= a+b; return(suma); } void escribir (int x) {cout<<x<<endl; -getch(); }

// prog042.cpp: define el punto de entrada de la aplicacin de consola. //funciones #include "stdafx.h" #include "iostream" #include "conio.h" using namespace std; void leer(float *px, float*pe); float expo(float x , float max_error); void escribir(float z); int _tmain(int argc, _TCHAR* argv[]) {float x, error; float expx; leer(&x,&error); expx= expo(x,error); cout<<"exp(x)=";escribir(expx); return 0; }

void leer(float *px,float *pe) {cout<<"ingrese argumento=>"; cin>>(*px); cout<<"ingrese error=>"; cin>>(*pe); } float expo(float x, float max_error) {int cont; float term, error_est; float exp1=1; cont=1; term=1; error_est=1.0; while(error_est>max_error) {term=term*(x/cont); exp1=exp1+term; cont ++; } return(exp1); } void escribir(float z) {cout<<z<<endl; -getch(); }

prog042.cpp: define el punto de entrada de la aplicacin de consola. //funciones #include "stdafx.h" #include "iostream" #include "conio.h" using namespace std; void leer(float *px, float*pe); float expo(float x , float max_error); void escribir(float z); int _tmain(int argc, _TCHAR* argv[]) {float x, error; float expx; leer(&x,&error); expx= expo(x,error); cout<<"exp(x)=";escribir(expx); return 0; } void leer(float *px,float *pe) {cout<<"\n\n ingrese argumento="; cin>>(*px); cout<<"ingrese error="; cin>>(*pe); } float expo(float x, float max_error) {int cont; float term, error_est; float exp1; exp1=1.0; cont=1;

term=1.0; error_est=1.0; while(error_est>max_error) { term=term*(x/cont); exp1=exp1+term; cont ++; error_est=term*(x/cont); } return(exp1); } void escribir(float z) {cout<<z<<endl; _getch(); }

También podría gustarte