#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand(time(0));
for( int i=1;i<=20;i++){
cout<<setw(10)<<(1+rand()%6);
if (i%5==0) { cout<<endl; }
}
unsigned seed;
cout<<"Ingrese semilla: ";cin>>seed;
srand(seed);
for( int i=1;i<=20;i++){
cout<<setw(10)<<(1+rand()%6);
if (i%5==0)
cout<<endl;
}
// use #include <ctime>
// para ejecutar srand(time(0))
system("PAUSE");
}
#include <iostream>
#include <cstdlib>
using namespace std;
float f_pol(float,int);//prototipo
int main(){
float x; int n;
cout<<"x=";cin>>x;
cout<<"n=";cin>>n;
cout<<"p(x)="<<f_pol(x,n)<<endl;
system("PAUSE");
}
float f_pol(float x,int n){
float z=1,t=1;
for (int i=1;i<=n;t*=x,z+=t,i++);
return z;
}
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
float hipo1(float,float);
void hipo2(float,float, float&);
int main(){
float a,b,c;
cout<<"(a,b)=";cin>>a>>b;
cout<<"c="<<hipo1(a,b)<<endl;
hipo2(a,b,c);
cout<<"c="<<c<<endl;
system("PAUSE");
}
float hipo1(float a,float b){
return sqrt(a*a+b*b);}
void hipo2(float a,float b,float& c){
c = sqrt(a*a+b*b);}
#include <iostream>
#include <cstdlib>
using namespace std;
float eval(float[],float,int);
int main(){
float x;int n;
float A[]={1, 3,-4,5};
n=4;
cout<<"x=";cin>>x;
cout<<"p(x)="<<eval(A,x,n)<<endl;
system("PAUSE");
}
float eval(float A[],float x,int n){
float z=0,t=1;
for(int i=0;i<n;z+=t*A[i++],t*=x);
return z;
}
#include <iostream>
#include <cstdlib>
using namespace std;
int dias_del_mes(int );
int main(){
int m;
do {
cout<<"mes(1-12)=";cin>>m;
}while( m<1 || m>12 );
cout<<"tiene "<<
dias_del_mes(m)<<endl;
system("PAUSE");
}
int dias_del_mes(int m){
switch(m){
case 1:case 3:case 5:
case 7:case 8:case 10:case 12: return 31;
case 4:case 6:case 9:case 11: return 30;
case 2: return 28;
}
}
No hay comentarios:
Publicar un comentario