+ 1

Help me please

Create a function that changes the first and last row of the square in places and finds the product of the main diagonal elements.

9th Jan 2019, 1:07 PM
Infnity
Infnity - avatar
3 Answers
+ 8
I am finding it difficult to understand what you wrote as I am not used to the language. Can you write in English ??
9th Jan 2019, 4:19 PM
Nova
Nova - avatar
+ 7
Hello Infinity !!! Welcome to Sololearn. Can you show your attempt first ?? We will definitely help you but first try to code yourself.
9th Jan 2019, 1:41 PM
Nova
Nova - avatar
0
#include <stdio.h> #include "stdafx.h" #define H 3 #define W 3 long swapUmn(int *matrix,int h,int w); void main(){ int matrix[H][W] = { {1,2,3}, {4,5,6}, {7,8,9} }; printf("transform\n"); long prDiag = swapUmn(&matrix[0][0],H,W); //трансформируем, и получаем произведени элемнетов диагонали //выводим результат for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ printf(" "); printf("%d",matrix[i][j]); } printf("\n"); } printf("\n"); //выводим произведение элементов диагонали printf("%d",prDiag); printf("\n"); getch(); } long swapUmn(int *matrix,int h,int w){ int i = 0; //первая строка int j = h-1; //последня строка int s = 0; //индекс столбца //Обмен последней строки и первой for(;s<w;s++){ int tmp = matrix[i*w+s]; matrix[i*w+s] = matrix[j*w+s]; matrix[j*w+s]=tmp; } //Находим произведение элементов диагонали int pr = 1; for(int q = 0,k=0;q<h||k<w;q++,k++)pr*=matrix[q*w+k]; return pr; }
9th Jan 2019, 2:09 PM
Infnity
Infnity - avatar