Está en la página 1de 3

EJERCICIO EN CLASE EN PRINTF Y COUT (C++)

MIGUEL ANGEL TOVAR

UNIVERSIDAD ANTONIO NARIÑO, SEDE BUGANVILES

PROGRAMA DE INGENIERÍA ELECTRONICA

NEIVA, HUILA

MAYO 2018

1) EN PRINTF
#include<iostream>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
int n,m,i,j;
int a[10][10],b[10][10],c[10][10];
system ("color b0");
printf("\n Suma de matrices");
printf("\n");
printf("\n Cuantas filas deseas?:");
scanf("%d",&n);
printf("\n Cuantas columnas deseas?:");
scanf("%d",&m);
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
{
printf("\nvalores de a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
printf("\nvalores de b[%d][%d]:",i,j);
scanf("%d",&b[i][j]);
c[i][j]=(a[i][j])+(b[i][j]);
}
printf("c=\n");

for(i=1;i<=n;i++) {

for(j=1;j<=m;j++) {

printf(" %d\t",c[i][j]);

}
return 0;
}

2) EN COUT
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int n,m,i,j;
int a[10][10], b[10][10],c[10][10];
system ("color b0");
cout<<"\n Suma de matrices"<<"\n"<<"\n Cuantas filas
deseas?:"<<ends;
cin>>n;
cout<<"\n Cuantas columnas deseas?:"<<ends;
cin>>m;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
{
cout<<"\n Valores de a["<<i<<"]"<<"
"<<"b["<<j<<"]:"<<ends;
cin>>a[i][j];
cout<<"\n Valores de b["<<i<<"]"<<"
"<<"b["<<j<<"]:"<<ends;
cin>>b[i][j];
c[i][j]=a[i][j]+b[i][j];
}
cout<<"\n c=\n"<<ends;
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
cout<<"\t"<<c[i][j]<<ends;
}
}
return 0;
}

También podría gustarte