Другие языки программирования и технологии

помогите переделать программу из С++ в Си

Main.cpp

#include <iostream>

float matrix[15][12], max=-99999, a, b, mo=0; int n, m;

#include "func.h"

void main()

{

input();

result();

print();

}

FUNC.H

void input()

{

std::cout << "vvedite razmernost' matrici";

std::cin >> n >> m;

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

{

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

{

std::cout << "vvedite element " << i
<< " "
<< j;

std::cin >>
matrix[i][j];

}

}

}

void result()

{

std::cout << "vvedite interval";

std::cin >> a >> b;

int
count = 0;

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

{

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

{

if (matrix[i][j] >= a && matrix[i][j] <= b)

{

if (max < matrix[i][j]) max = matrix[i][j];

count++;

}

}

}

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

{

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

{

if (matrix[i][j] >= a && matrix[i][j] <= b)

{

mo += matrix[i][j] /
count;

}

}

}

}

void print()

{

std::cout << "MO=" << mo << " max=" << max;

std::
cout << std::endl;

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

{

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

{

std::cout <<
matrix[i][j]<<" ";

}

std::cout << std::endl;

}

system("pause");
}
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
float matrix[15][12], max = -99999, a, b, mo = 0;
int n, m;
void input();
void result();
void print();
void main() {
input();
result();
print();
}
void input() {
int r, c;
setlocale(0, "");
printf(" Введите количество строк в матрице: ");
scanf_s("%i", &n);
printf(" Введите количество столбцов в матрице: ");
scanf_s("%i", &m);
for (r = 0; r < n; r++) {
for (c = 0; c < m; c++) {
printf(" matrix[%i][%i] -> ", r, c);
scanf_s("%f", &matrix[r][c]);
}
}
}
void result() {
int r, c;
printf(" Введите интервал a: ");
scanf_s("%f", &a);
printf(" Введите интервал b: ");
scanf_s("%f", &b);
int count = 0;
for (r = 0; r < n; ++r) for (c = 0; c < m; ++c) if (matrix[r][c] >= a && matrix[r][c] <= b) if (max < matrix[r][c]) max = matrix[r][c]; ++count;
for (r = 0; r < n; ++r) for (c = 0; c < m; ++c) if (matrix[r][c] >= a && matrix[r][c] <= b) mo += matrix[r][c] / count;
}
void print() {
int r, c;
printf(" MO = %f max = %f\n", mo, max);
for (r = 0; r < n; ++r, printf("\n")) for (c = 0; c < m; ++c) printf(" %f", matrix[r][c]);
system("pause");
}
Юрий Одиашвили
Юрий Одиашвили
89 743
Лучший ответ
iostream библиотеку меняем на stdio.h вместо cin юзаем scanf вместо cout используем printf. Об использований этих функций неплохо пишет википедия по гугловскому запросу "Стандартная библиотека С". И auto замените, он есть только в специализации C++11.