You are on page 1of 8

Parte-1:

Ex-1
#include <iostream>
using namespace std;

int main(){
float x;

do {
cout << "Deme tu nota \n";
cin >> x;
}while((x < 0) || ( x> 10));

if(x>=0 && x < 5)


cout << "Suspenso \n";

if(x>=5 && x < 7)


cout << "Aprobado \n";

if(x>=7 && x < 9)


cout << "Notable \n";

if(x>=9 && x < 10)


cout << "Sobresaliente \n";

if(x==10)
cout << "Matricula de Honor \n";
}
Ex-2:
#include <iostream>
using namespace std;

int main(){
int N, s = 0, r;

cout << "Deme un entro \n";


cin >> N;

while(N != 0){
r = N%10;
s = s + r;
N = N/10;
}
cout << "La suma de los digitos es: " << s << endl;
}
Ex-3:
#include <iostream>
using namespace std;

int main(){
int N, r, rev = 0;
cout << "Deme un entro \n";
cin >> N;
while(N != 0){
r = N%10;
rev = 10*rev+ r;
N = N/10;
}
cout << "El numero escrito al revés es :" << rev << endl;
}
Parte-2 :

Ex-1:
#include <iostream>
using namespace std;

float fs(float, float);


float fp(float, float);

float fs(float r1, float r2){


return (r1 + r2);
}

float fp(float r1, float r2){


float re;
re = (r1*r2)/(r1 + r2);
return re;
}

int main(){
float r1=1.5, r2=1.3, r3=0.5, r4=1, r5=1, re1, re2;

re1 = fp(fs(r1, r5), fs(fs(r2, r3), r4));


re2 = fs(fp(r1, r3), fp(r2, r4));

cout << re1 << endl;


cout << re2 << endl;
}

Ex-2
#include <iostream>
using namespace std;

long unsigned int fn(unsigned int);


long unsigned int fn(unsigned int n){
long unsigned int p = 1;

if (n == 0)
return 1;
for(int i=1; i <=n; i++) {
p = p*i;
}
return p;
}

int main() {
int m, n, c;

cout << "Introduzca el valor de m y n ; (m >=n) \n";


cin >> m >> n;

c = fn(m)/(fn(n)*fn(m-n));

cout << c << endl;


}
Ex-3
/* Programa organizado en funciones que pide los lados de
triangulo rectangulo.
1. Perimetro
2. Hipotenusa
3. Area
*/
#include <iostream>
#include <math.h>
using namespace std;

float perimetro(float, float);


float hipotenusa(float, float);
float area(float, float);

float area(float a, float b){


return (a*b)/2;
}

float hipotenusa(float a, float b){


float x;
x = sqrt(a*a + b*b);
return x;
}
float perimetro(float a, float b){
float p;
p = a + b + hipotenusa(a, b);
return p;
}

int main() {
float a, b;

cout << "Introduzca a y b \n";


cin >> a >> b;

cout << "El perimetro es : " << perimetro(a, b) << endl;


cout << "La hipotenusa es : " << hipotenusa(a, b) << endl;
cout << "El area es : " << area(a, b) << endl;
}
Parte-3 :

Ex-1:
#include <iostream>
using namespace std;

void notas(float, float, float, float *, float *, float *);


void notas(float x1, float x2, float x3, float *media, float *mejor,
float *peor){
float temp;

//media
*media = (x1+x2+x3)/3.0;

//mejor
if(x1 > x2)
temp = x1;
else
temp = x2;

if(temp > x3)


*mejor = temp;
else
*mejor = x3;

//peor
if(x1 > x2)
temp = x2;
else
temp = x1;

if(temp > x3)


*peor = x3;
else
*peor = temp;
}

int main () {
float n1, n2, n3, media, mejor, peor;

cout << "Introduzca 3 notas \n" ;


cin >> n1 >> n2 >> n3;

notas(n1, n2, n3, &media, &mejor, &peor);

cout << "La media: " << media << endl;


cout << "La mejor: " << mejor << endl;
cout << "La peor: " << peor << endl;
}

Ex-2:
#include <iostream>
using namespace std;

#define DIM 10
void addVectors(float [], float [], float [], int);
void concatVectors(float [], float [], float [], int, int);
void printVector(float [], int);
float prodEscalar(float [], float [], int);

void concatVectors(float a[], float b[], float c[], int na, int nb){
for (int i = 0; i < na; i++)
c[i] = a[i];
for (int i = 0; i < nb; i++)
c[na + i] = b[i];
}
void addVectors(float a[], float b[], float c[], int nc){
for(int i=0; i<nc ; ++i)
c[i]=a[i]+b[i];
}
void printVector(float a[], int n){
for(int i=0; i<n ; ++i)
cout << a[i] << " ";
cout << endl;
}

float prodEscalar(float a[], float b[], int n){


float s=0;
for(int i=0; i< n; i++)
s = s + a[i]*b[i];
return s;
}

int main(){
float v1[DIM]={1,2,3,4}, v2[DIM]={2,4,6,8}, v3[DIM]={};
int d = 4;
float x1[DIM]={1,2,3,4}, x2[DIM]={0, 6,8}, x3[DIM]={};
int d1 = 4, d2 = 3;

printVector(v1, d);
printVector(v2, d);
addVectors(v1, v2, v3,d); //Function call
printVector(v3, d);

concatVectors(x1, x2, x3, d1, d2); //Function call


printVector(x3, d1+d2);
cout << "El producto escalar es: " << prodEscalar(v1, v1, d) << endl;
}

Ej3 :
#include <iostream>
using namespace std;
#define DimF 10
#define DimC 10

void printMatrix(float [][DimC], int, int); //Print a matrix


void addMatrix(float [][DimC], float [][DimC], float [][DimC], int,
int); //add matrix
void prodMatrix(float [][DimC], float [][DimC], float [][DimC],
int); //prod matrix
void traspuestaMatrix(float [][DimC], float [][DimC], int,
int); //Traspuesta matrix

void traspuestaMatrix(float m[][DimC], float mt[][DimC], int f, int c)


{
int i, j;
for(i=0; i<f; i++){
for(j=0; j<c; j++)
mt[j][i] =m[i][j];
}
}
void printMatrix(float m[][DimC], int f, int c){
int i, j;
for(i=0; i<f; i++){
for(j=0; j<c; j++)
cout << " " << m[i][j];
cout << endl;
}
cout << endl;
}

void addMatrix(float a[][DimC], float b[][DimC], float c[][DimC], int


nf, int nc){
for(int i=0; i < nf; i++){
for(int j=0; j < nc; j++)
c[i][j] = a[i][j] +b[i][j];
}
}

void prodMatrix(float a[][DimC], float b[][DimC], float c[][DimC],


int n){
float s = 0;
for(int i=0; i < n; i++){ //Ubicados en una fila
for(int j=0; j < n; j++){ //Ubicados en una columna
s=0;
for(int k=0; k<n; k++){ //producto de la fila-i x la
columna-j
s = s + a[i][k]*b[k][j];
}
c[i][j] = s;
}
}
}

int main(){
int n, nf = 3, nc = 4; // Matrix dimensions
float A[DimF][DimC]={{1, 2, 3,4}, {5, 6, 7, 8}, { 9,10, 11,12}};
float B[DimF][DimC]={{1, -2, -3,-4}, {5, -6, -7, -8}, {9,-10, -11,-
12}};
float C[DimF][DimC]={};

float m1[DimF][DimC]={{1, 2, 3}, {5, 6, 7}, {9,10, 11}};


float m2[DimF][DimC]={{2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
float m3[DimF][DimC]={};

traspuestaMatrix(A,C,nf, nc);
printMatrix(A, nf, nc); //Function call
printMatrix(C, nc, nf); //Function call

/*
addMatrix(A, B, C, nf, nc);
printMatrix(A, nf, nc);
printMatrix(B, nf, nc);
printMatrix(C, nf, nc);
n = 3;
prodMatrix(m1, m2, m3, n);
printMatrix(m1, n, n);
printMatrix(m2, n, n);
printMatrix(m3, n, n);
*/
}
Ej-1 (P4)
#include <iostream>
#include <math.h>
using namespace std;

typedef struct{
float r;
float i;
} CMPX;

void print_cx(CMPX);
float abs_cx(CMPX);

CMPX add_cx(CMPX, CMPX);


CMPX sub_cx(CMPX, CMPX);
CMPX mul_cx(CMPX, CMPX);
CMPX conj_cx(CMPX);

void print_cx(CMPX z){


cout << z.r << " + " << z.i << "j" << endl ;
}

CMPX add_cx(CMPX a, CMPX b){


CMPX z;
z.r = a.r + b.r;
z.i = a.i + b.i;
return z;
}

CMPX sub_cx(CMPX a, CMPX b){


CMPX z;
z.r = a.r - b.r;
z.i = a.i - b.i;

return z;
}
CMPX conj_cx(CMPX a){
CMPX z;
z.r = a.r;
z.i = -a.i;
return z;
}
// z1 = a + bi ; z2 = c + di
// z = z1*z2 = (ac-bd) + (ad+bc)j
CMPX mul_cx(CMPX z1, CMPX z2){
CMPX z;
z.r = z1.r * z2.r - z1.i*z2.i;
z.i = z1.r * z2.i + z1.i*z2.r;

return z;
}

float abs_cx(CMPX z){

return sqrt((z.r)*(z.r) + (z.i)*(z.i));


}

int main(){
CMPX i={0, 1}, z={1,1};

//z2 = add_cx(z1, z1);


//z = mul_cx(i, i);
//print_cx(z);
cout << abs_cx(z) << endl;

You might also like