Предмет: Информатика, автор: 8903artyuhov

Составить программу на С++ одной программой, в которой
1) организовать ввод квадратной матрицы размера nxn из целых чисел;
2) возвести в квадрат все отрицательные элементы матрицы;
3) переставить нулевые элементы первой строки матрицы в ее начало;
4) организовать ввод и вывод матрицы в виде отдельных функций.

Ответы

Автор ответа: Аноним
0

#include <stdio.h>


/* организовать ввод и вывод матрицы в виде отдельных функций. */


void scanMatrix(unsigned n, int matrix[n][n])

{

   printf("Enter matrix elements, separated by spaces:\n");


   for (unsigned i = 0; i < n; i++)

   {

       for (unsigned j = 0; j < n; j++)

       {

           scanf("%d", &matrix[i][j]);

       }

   }

}


void printMatrix(unsigned n, int matrix[n][n])

{

   printf("These are matrix elements:\n");


   for (unsigned i = 0; i < n; i++)

   {

       for (unsigned j = 0; j < n; j++)

       {

           printf("%d ", matrix[i][j]);

       }

       printf("\n");

   }

}


int main()

{

   unsigned n;


   /* организовать ввод квадратной матрицы размера nxn из целых чисел; */

   printf("Enter matrix dimension: ");

   scanf("%u", &n);


   int matrix[n][n];

   scanMatrix(n, matrix);


   /* возвести в квадрат все отрицательные элементы матрицы; */

   for (unsigned i = 0; i < n; i++)

   {

       for (unsigned j = 0; j < n; j++)

       {

           if (matrix[i][j] < 0)

           {

               matrix[i][j] *= matrix[i][j];

           }

       }

   }


   /* переставить нулевые элементы первой строки матрицы в ее начало; */

   unsigned lastReplacableIndex = 0;

   for (unsigned i = 1; i < n; i++)

   {

       if (matrix[0][i] == 0)

       {

           int temp = matrix[0][lastReplacableIndex];

           matrix[0][lastReplacableIndex] = matrix[0][i];

           matrix[0][i] = temp;

           lastReplacableIndex++;

       }

   }


   printMatrix(n, matrix);

}

Похожие вопросы
Предмет: Биология, автор: dianatalalaeva7544
Предмет: Алгебра, автор: lera0019
Предмет: Английский язык, автор: sahinakuldaseva564
READING 4. Read and say True or False. The planet Pluto was opened in 1930. It was named by an 11-year old girl from England. Since then many people grew up thinking that Pluto was the ninth planet of the Solar System. Its diameter is only 2,372 km. It is so far from earth that the most powerful telescopes could only show Pluto as a grey image in the Kuiper belt. The Kuiper belt is home to hundreds of thousands of icy, rocky objects, many bigger than 100 km across and over 1 trillion or more comets. Since 2006, little Pluto is no longer a main planet but a dwarf planet because of its size. Pluto is the largest dwarf planet discovered so far. Pluto is smaller than our moon and it is a strange world that has alleys, plains, mountains, and possibly ice. It has five moons and the biggest moon is Charon, which is almost half the size of Pluto. The temperature on its surface is -229 degrees C. It is thanks to the New Horizon spaceship that we have learned so much about Pluto and its hard area. New Horizon also showed that Pluto's area has mountains as tall as 3,500 m which are close to the size of Earth's Rocky Mountains in the USA. One day on Pluto takes about 153 hours. For Pluto it takes 246 earth days to make a full orbit of the sun. Sunlight on Pluto looks like moonlight on Earth. 1) Pluto was known by the scientists before 1930. 2) Pluto was a girl's name. 3) Pluto's diameter is more than 2000 km. 4) The Kuiper belt consists of rocks, comets and planets. 5) After 2006 Pluto has been called a dwarf planet. 6) The moon is bigger than Pluto. 7) The New Horizon spaceship discovered Pluto's area. 8) The sunlight is very bright on Pluto.​
Предмет: Математика, автор: 79067539811