сонька177
17.02.2021 15:54

Дана целочисленная матрица M(6, 8). Напечатать все ее столбцы, в которых одинаковое количество элементов, оканчивающихся на цифру 8. Если таких столбцов нет, то выдать сообщение об этом С# вывести в windows forms

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
borik7777
05.08.2020 12:55
/* 1 */

#include <stdio.h>

struct Point {
    double x, y;
};

struct Point fillPoint(unsigned short int id) {
    struct Point p;
    printf("Точка №%d\n", id);
    printf("x = ");
    scanf("%lf", &(p.x));
    printf("y = ");
    scanf("%lf", &(p.y));
    return p;
}

int pointsInSameQuarter(struct Point p1, struct Point p2) {
    if ( ( (p1.x > 0) && (p2.x > 0) ) || ( (p1.x < 0) && (p2.x < 0) ) ) { /* xs */
        if ( ( (p1.y > 0) && (p2.y > 0) ) || ( (p1.y < 0) && (p2.y < 0) ) ) { /* ys */
            return 1;
        }
    }
    return 0;
}

int main() {
    struct Point p1 = fillPoint(1), p2 = fillPoint(2);
    printf("Точки %sв одной координатной четверти", (pointsInSameQuarter(p1, p2) ? "" : "не "));
}

/* 2 */

#include <stdio.h>
#include <math.h>

int main() {
    int x;
    printf("x = ");
    scanf("%d", &x);
    float r;
    int c = 0;
    for (int d = 1; d <= x; d++) {
        r = (float) x / d;
        if ( ceilf(r) == r ) c++;
    }
    printf("ответ: %d", c);
}
0,0(0 оценок)
Ответ:
Eclipse2345
31.10.2021 15:48
Подходит как и на C++ Так и на C#

internal class Program

{

 

   private static void Main(string[] args)

   {

       int n = 8;

       int m = 10;

       int[,] matrix = createRandomMatrix(n, m);

       writeMatrix(matrix);

 

       for (int i = 0; i < m; i++)

       {

           int count = 0;

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

           {

               if (matrix[j, i] >= 0) count++;

               else count--;

           }

 

           if (count == 0) Console.WriteLine($"Столбец номер {i+1} с одинаковым кол-вом положительных и отрицательных элементов.");

       }

 

   }

 

 

   private static int[,] createRandomMatrix(int n, int m)

   {

       Random rand = new Random();

       int[,] matrix = new int[n, m];

 

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

       {

           for (int j = 0; j < m; j++)

           {

               matrix[i, j] = rand.Next(-10, 11);

           }

       }

       return matrix;

   }

 

   private static void writeMatrix(int[,] matrix )

   {

       string row = "";

       int[] tempRow = new int[matrix.GetLength(1)];

       for (int i = 0; i < matrix.GetLength(0); i++)

       {

           for (int j = 0; j < matrix.GetLength(1); j++)

           {

               tempRow[j] = matrix[i, j];

           }

           row += string.Join("\t", tempRow) + "\n";

       }

       Console.WriteLine(row);

   }

}

Объяснение:

0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота