{
int a[3][3];
int i,j,n;
int max=0, second_max=0;
cout<<"Enter the numbers in the array sequentially"; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>n;
a[i][j]=n;
}
}
// With this all the required numbers have been inserted into the array successfully as per the user's choice.This is a 3X3 array...You can change the size as per ur choice.
for(i=0;i<3;i++) { for(j=0;j<3;j++) { (if(a[i][j]>a[i][j+1])&&(a[i][j]>max))
{
max=a[i][j];
//This max has the highest element.
}
}
}
//But we have to find the second largest element...so compare all the elements again with themselves and with the max
for(i=0;i<3;i++) { for(j=0;j<3;j++) { (if(a[i][j]>a[i][j+1])&&(a[i][j]
{
second_max=a[i][j];
//This max has the highest element.
}
}
}
//Now, we have the second largest element print it out.
Cout<<"The second largest element is<
}
No comments:
Post a Comment