Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result



Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a sepa..

Answer / Rajani Sachan

In C, you can implement this as follows:n```cnint i, j, sum_upper = 0, sum_lower = 0;nfor (i = 0; i < M; i++) {n for (j = i + 1; j < N; j++) {n if (i < j) {n sum_upper += matrix[i][j];n } else if (i > j)n sum_lower += matrix[j][i];n }n}nprintf("Upper diagonal: %d
Lower diagonal: %d
", sum_upper, sum_lower);n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What type of function is main ()?

1 Answers  


Tell me what is the purpose of 'register' keyword in c language?

1 Answers  


Is c is a high level language?

1 Answers  


write a c programs to do multiplication of two numbers with out using arithmatic operator ??????????

7 Answers   Infosys, TCS,


WHAT IS HEADER?

8 Answers   ProKarma, TCS,


What is the function of volatile in c language?

1 Answers  


What is the -> in c?

1 Answers  


Differentiate b/w Modify and Update commands giving example.

1 Answers  


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

1 Answers  


to get a line of text and count the number of vowels in it

3 Answers   Satyam,


What is the explanation for prototype function in c?

1 Answers  


write a c program to print a given number as odd or even without using loop statements,(no if ,while etc)

10 Answers  


Categories