jueves, 24 de octubre de 2013

Solucion del examen parcial: Tema MRU

01)
a.-
#include <iostream>

using namespace std;

int main()
{
   int i,j;
 
   for (j=1;j<4;j++){
     for (i=j;i<4;i++)
       cout<<i<<endl;
   }
 
}
b.-
1
2
3
2
3
3

02)
#include <iostream>

using namespace std;

int main()
{
   float D,V,T;
   cout<<"D=";cin>>D;
   cout<<"V=";cin>>V;
   cout<<"T=";cin>>T;
   bool p,q,r;
   p=(D>0);
   q=(V>0);
   r=(T>0);
   if ( p && q && r){
       if (D==V*T)
         cout<<"Es MRU"<<endl;
       else
         cout<<"No es MRU"<<endl;
   }
   else{
       if (p && q){
          T=D/V;
          cout<<"Recalculamos T"<<endl;
       } else if (p && r){
          V=D/T;
          cout<<"Recalculamos V"<<endl;
       }else if (q && r){
          D=V*T;
          cout<<"Recalculamos D"<<endl;
       }else
         cout<<"Datos insuficientes"<<endl;
   }
   cout<<"D="<<D<<", V="<<V<<", T="<<T<<endl;
}

Solucion del examen parcial: Tema: Ley de Ohm



Pregunta 01

a)
#include <iostream>

using namespace std;

int main()
{
   int i,j;
   
   for (j=1;j<6;j++){
     for (i=j;i<6;i+=2)
       cout<<i<<endl;
   }
   
}

b)
1
3
5
2
4
3
5
4
5

Pregunta 02

#include <iostream>

using namespace std;

int main()
{
   float I,V,R;
   cout<<"I=";cin>>I;
   cout<<"V=";cin>>V;
   cout<<"R=";cin>>R;
   bool p,q,r;
   p=(I>0);
   q=(V>0);
   r=(R>0);
   if ( p && q && r){
       if (V==I*R)
         cout<<"Cumple la ley de Ohm"<<endl;
       else
         cout<<"No cumple la ley de Ohm"<<endl;
   }
   else{
       if (p && q){
          R=V/I;
          cout<<"Recalculamos R"<<endl;
       } else if (p && r){
          V=I*R;
          cout<<"Recalculamos V"<<endl;
       }else if (q && r){
          I=V/R;
          cout<<"Recalculamos I"<<endl;
       }else
         cout<<"Datos insuficientes"<<endl;  
   }
   cout<<"I="<<I<<", V="<<V<<", R="<<R<<endl;
}

jueves, 17 de octubre de 2013

Desviacion estandar

#include <iostream>
#include <cmath>
using namespace std;
int main(){
  float* x; int n;
  float s=0,m=0;
  cout<<"n=";cin>>n;
  x=new float[n];
  for (int i=0;i<n;i++){
      cout<<"Ingrese valor "<<i+1<<":";
      cin>>x[i];m+=x[i];
  }
  m/=n;
  for (int i=0;i<n;i++){
      s+=pow(x[i]-m,2);
  }
  s=sqrt(s/(n-1));
  cout<<"Media="<<m<<", D.E="<<s<<endl;
  cin.get();  cin.get();
 }

Permutaciones

#include <iostream>
using namespace std;
int main(){
  float c,n,r;
  cout<<"n=";cin>>n;
  cout<<"r=";cin>>r;
  c=1;
  if (n>r){
     for (int i=n-r;i>=1;i--){
       c*=(i+r)/i;
     }
  }
  cout<<"c="<<c<<endl;
  cin.get();  cin.get();
 }

mostrar horas, minutos y segundos

#include <iostream>
#include <string>
using namespace std;
int main(){
  string destino;
  float velocidad,distancia;
  int horas,minutos,segundos;
  cout<<"Ingrese destino: ";
  cin>>destino;
  cout<<"Ingrese distancia: ";
  cin>>distancia; 
  cout<<"Ingrese velocidad: ";
  cin>>velocidad;
  float t=distancia/velocidad;
  horas = (int) t;
  minutos =(int)((t-horas)*60);
  segundos =(int)(((t-horas)*60-minutos)*60);
  cout<<horas<<":"<<minutos<<":"
      <<segundos<<endl;
  cin.get();  cin.get();
}

Convertir grados Farenheit a Celsius

#include <iostream>
using namespace std;
int main(){
  float C,F,K;
  cout<<"Ingrese Temperatura (C): ";
  cin>>C;
  F = 9.0/5*C + 32;
  K = C+273;
  cout<<"es equivalente a:"
  <<F<<" F"<<" o "<<K<<" K"<<endl;
  cin.get();  cin.get();
}

jueves, 10 de octubre de 2013

pregunta 3

#include <iostream>
using namespace std;
int main(){
    int H,K,R,n=0;
    cout<<"H=";cin>>H;
    cout<<"K=";cin>>K;
    cout<<"R=";cin>>R;
    for (int i=1;i<H+R;i++)
      for (int j=1;j<K+R;j++){
        float d=(i-H)*(i-H)+(j-K)*(j-K);
        n+=( (d<R*R)?1:0);
      }
    cout<<"Hay "<<n<< "puntos."<<endl;
    cin.get();    cin.get();
}