im trying to find the largest number from a selected row of an matrix. My code is ok until i insert negative numbers. I don't know what to write for solvinng this...
#include<iostream>
#include<cstdlib>
using namespace std;
int main ()
{
int rang=10,i,j, M[rang][rang],n,k,max=0;
char answer;
do{
do{cout<<"Insert the matrix rank(max. 10): "; cin>>n; }
while(n<1||n>rang);
cout<<"Insert elements: "<<endl;
for(i=0;i<n;i++)
for(j=0;j<n;j++){cout<<"M["<<i<<"]["<<j<<"]= "; cin>>M[i][j];}
cout<<endl;
for(int i=0; i<n;i++){ for(int j=0;j<n;j++) cout<<"\t"<<M[i][j]; cout<<"\n\n";}
do{ cout<<"Select a row: "; cin>>k;}
while(k<0||k>n);
for(j=0;j<n;j++)
if (max<M[k-1][j]){max=M[k-1][j];}
cout<<"The largest number of the "<<k<<" row is "<<max<<endl ;
cout << "Try again? (Y/N): ";
cin >> answer;
cout << endl;
}
while(answer == 'Y' || answer == 'y');
}

New Topic/Question
Reply



MultiQuote









|