Question: I was creating a program that has a 2 dimensional array with 25 elements.How can I display the highest row sum? lowest row sum? highest col sum? lowest row sum?
Answer: Assuming that your array elements are non negative, Initialize static variables highest RowSum & highest ColumnSum to ZERO. Keep calculating sum of each row & column in for loops and simultaneously keep comparing & assigning the rowSum & columnSum with static variables highestRowSum and highestColumnSum respectively if the earlier values are higher. Similarly you can do to get the lowest values but the static variables should be intialized to a MAX number. Hope this answers without furnishing a code snippet!
Category
Input and Output Operations in C++ Interview Questions & Answers -
Exam Mode /
Learning Mode
Rating
(0.2) By 9262 users
Added on
5/19/2013
Views
68901
Rate it!
Question:
I was creating a program that has a 2 dimensional array with 25 elements.How can I display the highest row sum? lowest row sum? highest col sum? lowest row sum? Answer:
Assuming that your array elements are non negative, Initialize static variables highest RowSum & highest ColumnSum to ZERO. Keep calculating sum of each row & column in for loops and simultaneously keep comparing & assigning the rowSum & columnSum with static variables highestRowSum and highestColumnSum respectively if the earlier values are higher. Similarly you can do to get the lowest values but the static variables should be intialized to a MAX number. Hope this answers without furnishing a code snippet! Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
There should not be any Spelling Mistakes.
There should not be any Gramatical Errors.
Answers must not contain any bad words.
Answers should not be the repeat of same answer, already approved.
Answer should be complete in itself.
Related Questions
View Answer
Help me to write a c++ program using strings that does the following tasks 1)Removes multiple spaces between words. 2)find the longest word in a text. 3)extract the number of integers in the text. 4)extract the number of doubles.5)extract the number of words in a sentence.
What will be output of the following code #include using namespace std; class abc { public : void main() { cout<<" Its main function "< } }; int main(int c, char **v) { abc a; if(c<1) { cout<<" Error can not accept it "< exit(1); } cout<<" its in main program "< a.main();