Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <locale.h>
- #include <cstdlib>
- float** read_matr(char *fille, int *n){
- FILE *myfile;
- errno_t err;
- err = fopen_s(&myfile, "text.txt", "r");
- if (err != 0){
- printf("Файл не может быть открыт или создан\n");
- //return NULL;
- }
- fscanf_s(myfile, "%i", n);
- printf("%i",*n);
- float **matr;
- system("pause");
- matr = (float**)malloc((*n) * sizeof(float*));
- for (int i = 0; i < *n; i++) {
- *(matr+i) = (float*)malloc((*n) * sizeof(float));
- }
- printf("Память\n");
- system("pause");
- for (int i = 0; i < *n; i++)
- {
- for (int j = 0; j < *n; j++) {
- fscanf_s(myfile, "%f", (*(matr + i) + j));
- }
- }
- system("pause");
- fclose(myfile);
- return matr;
- }
- int print_matr(float **matr, int *n){
- for (int i = 0; i < *n; i++){
- for (int j = 0; j < *n; j++) {
- printf(" %.2f ", matr[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
- float **calc_B(int n){
- float** b = (float**)malloc(n * sizeof(float*));
- for (int i = 0; i < n; i++)
- {
- *(b + i) = (float*)malloc(n * sizeof(float));
- }
- for (int i = 0; i < n; i++){
- for (int j = 0; j < n; j++)
- {
- *(*(b + i) + j) = (float)abs(i + j) / (2 + i + j*j);
- }
- }
- return 0;
- }
- float calc_E(int n)
- {
- float** e = (float**)malloc(n * sizeof(float*));
- for (int i = 0; i < n; i++){
- *(e + i) = (float*)malloc(n * sizeof(float));
- for (int j = 0; j<n; j++){
- if (i == j) {
- *(*(e + i) + j) = 1;
- }
- else *(*(e + i) + j) = 0;
- }
- }
- return 0;
- }
- //float calc_C ( float **matrA, float **matrB, float **matrE, int n)
- // {
- // float** matrC = (float**)malloc(n * sizeof(float*));
- // for ( int i = 0; i < n; i++)
- // {
- // *(matrC + i) = (float*)malloc(n * sizeof(float));
- // for ( int j = 0; j < n; j++)
- // {
- // matrC = (2 *(*(matrA + i) + j) + *(*(matrB i) + j + 2 * *(*(matrC + i) + j);
- // }
- // }
- //
- // return 0;
- // }
- int main(int argc, const char * argv[]) {
- setlocale(LC_ALL, "Russian");
- int n = 0;
- char *input_name, *output_name;
- input_name = (char*)malloc(255 * sizeof(char));
- output_name = (char*)malloc(255 * sizeof(char));
- float** A, **B, **C;
- printf("Введите имя файла, в котором хранится матрица А: ");
- gets_s(input_name,10);
- printf("%s", input_name);
- A = read_matr(input_name, &n);
- print_matr(A, &n);
- B = calc_B(n);
- print_matr(B, &n);
- // C=calc_C(A,B,n);
- // print_matr(С,n);
- // printf("Введите имя файла для записи матрицы С: ");
- // scanf_s("%s", output_name);
- // write_matr(output_name,C,n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement