0% found this document useful (0 votes)
16 views3 pages

Message

This C++ program allows the user to perform subtraction or addition on 2D arrays. It uses gotoxy functions to position input/output at specific screen coordinates. For subtraction, it prompts the user to input values for 2 4x4 arrays, calculates their difference element-wise, and displays the result. For addition, it similarly inputs a 5x3 array, sums elements in each row that are odd numbers, and displays the row totals. The program loops until the user selects the 'S' option to exit.

Uploaded by

vldo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Message

This C++ program allows the user to perform subtraction or addition on 2D arrays. It uses gotoxy functions to position input/output at specific screen coordinates. For subtraction, it prompts the user to input values for 2 4x4 arrays, calculates their difference element-wise, and displays the result. For addition, it similarly inputs a 5x3 array, sums elements in each row that are odd numbers, and displays the row totals. The program loops until the user selects the 'S' option to exit.

Uploaded by

vldo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

using namespace std;


#include <windows.h>

void gotoxy(int x, int y) {


HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
SetConsoleCursorPosition(hcon, dwPos);
}

int main()
{
char opc;
int i, j, k, l, m;
int temp = 0, valid = 1;
int arr1[4][4], arr2[4][4], arrR[4][4], arrA[5][3], arrRA[5] = {0,0,0,0,0};
do {
cout << "[A]Resta\n[B]Suma\n[S]Salir" << endl;
cin >> opc;
opc = toupper(opc);
switch (opc) {
case 'A':
system("cls");
for (i = 0; i < 4; i++) {
//A
for (j = 3; j >= 0; j--) {
//A
do {
valid = 1;
gotoxy(i * 10, j + 2); cout << " ";
gotoxy(i * 10, j + 2);
cin >> temp;
for (l = 0; l < 4; l++) {
for (k = 3; k >= 0; k--) {
if (arr1[k][l] == temp) valid = 0;
}
}
} while (valid == 0 || temp < 0);
arr1[j][i] = temp;
//A
}
}
for (i = 0; i < 4; i++) {
//A
for (j = 3; j >= 0; j--) {
//A
do {
valid = 1;
gotoxy(i * 10, j + 9); cout << " ";
gotoxy(i * 10, j + 9);
cin >> temp;
for (l = 0; l < 4; l++) {
for (k = 3; k >= 0; k--) {
if (arr1[k][l] == temp || arr2[k][l] == temp)
valid = 0;
}
}
} while (valid == 0 || temp < 0);
arr2[j][i] = temp;
//A
}
}
gotoxy(0, 15);
cout << "Arreglo Final: " << endl;
for (i = 3; i >= 0; i--) {
for (j = 3; j >= 0; j--) {
gotoxy(i * 10, j + 16);
if (arr1[j][i] > arr2[j][i]) {
arrR[j][i] = arr1[j][i] - arr2[j][i];
}
else {
arrR[j][i] = arr1[j][i];
}
cout << arrR[j][i];
}
}
gotoxy(0, 22);
system("pause");
system("cls");
break;
case 'B':
system("cls");
for (i = 0; i < 3; i++) {
//A
for (j = 0; j < 5; j++) {
//A
do {
valid = 1;
gotoxy(i * 10, j + 2); cout << " ";
gotoxy(i * 10, j + 2);
cin >> temp;
for (l = 0; l < 3; l++) {
for (k = 0; k < 5; k++) {
if (temp == 0 || temp == 1 || temp == 4) valid
= 0;
for (m = 2; m < temp / 2; m++) {

if (temp % m == 0) valid = 0;
}
if (arrA[k][l] == temp) valid = 0;

}
}
} while (valid == 0 || temp < 0);
arrA[j][i] = temp;
}
}
gotoxy(0, 15);
cout << "Arreglo Final: " << endl;
for (j = 0; j < 5; j++) {
//A
for (i = 0; i < 3; i++) {
//A
if (arrA[j][i] % 2 !=0) {
arrRA[j] += arrA[j][i];
}
}
}
for (j = 0; j < 5; j++) {
cout << arrRA[j] << endl;
}
gotoxy(0, 22);
system("pause");
system("cls");
break;
default:
if (opc != 'S') cout << "Opcion no valida." << endl;
break;
}
} while (opc != 'S');
}

You might also like