### Ordered Pair to Matrix Problem

Good day! So I have this code that creates matrices when ordered pairs are entered.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140`` ``````#include #include #include using namespace std; int matrix(); void ordPair(); int size, i, j, ans, matSize, haha; int mat[16][16]; int main() { int size, choice; do{ system("cls"); cout<<"[1] Matrix\n[2] Ordered Pair\nEnter choice: "; cin>>choice; switch(choice) { case 1: matrix(); break; case 2: ordPair(); break; default: break; } system("cls"); cout<<"Do you want to try again?\n[1] Yes\n[0] No\n"; cin>>ans; }while(ans!=0); getch(); return 0; } int matrix() { int size, i, j; int mat[10][10]; system("cls"); cout<<"[2] 2x2\n[3] 3x3\n[4] 4x4\nEnter choice: "; cin>>size; cout<<"Enter matrix elements(0 and 1 only)"<>mat[i][j]; } } system("cls"); cout<<"Displaying matrix: "<>matSize; if(matSize>4) { cout<<"Invalid input!!"<>size; do{if(size>matmat) { cout<<"Invalid input!!"<>size; }}while(size>matmat); for(i=1; i<=size; i++) { for(j=1;j<=size;j++) { pair[i][j]=0; } } for(int k=1; k<=size;k++) { cout<<"Enter domain["<>temp1; cout<<"Enter range["<>temp2; cout<

When I input a 4x4 matrix, and enter 4 ordered pairs, (1,1),(2,2),(3,3) and (4,4), it functions normally. But when I try a 2x2 matrix and input one ordered pair, (2,1), the output would be:
0 16842752
1 1973338893

Any idea why it prints out random numbers?
Thank you!
Last edited on
Topic archived. No new replies allowed.