вот,что получилось,ну так как не я считай писала, а мне еще и помогали,то чет не очень понимаю все....
#include "stdafx.h"
#include <stdio.h>
#include <process.h>
float **a, *b, *x;
int N;
char filename[256];
FILE* InFile=NULL;
void count_num_lines(){
//count number of lines in input file - number of equations
int nelf=0; //non empty line flag
do{
nelf = 0;
while(fgetc(InFile)!='\n' && !feof(InFile)) nelf=1;
if(nelf) N++;
}while(!feof(InFile));
}
void freematrix(){
//free memory for matrixes
int i;
for(i=0; i<N; i++){
delete [] a;
}
delete [] a;
delete [] b;
delete [] x;
}
void allocmatrix(){
//allocate memory for matrixes
int i,j;
x = new float[N];
b = new float[N];
a = new float*[N];
if(x==NULL || b==NULL || a==NULL){
printf("\nNot enough memory to allocate for %d equations.\n", N);
exit(-1);
}
for(i=0; i<N; i++){
a = new float[N];
if(a==NULL){
printf("\nNot enough memory to allocate for %d equations.\n", N);
}
}
for(i=0; i<N; i++){
for(j=0; j<N; j++){
a[j]=0;
}
b=0;
x=0;
}
}
void readmatrix(){
int i=0,j=0;
//read matrixes a and b from input file
for(i=0; i<N; i++){
for(j=0; j<N; j++){
fscanf(InFile, "%f", &a[j]);
}
fscanf(InFile, "%f", &b);
}
}
void printmatrix(){
//print matrix "a"
int i=0,j=0;
printf("\n");
for(i=0; i<N; i++){
for(j=0; j<N; j++){
printf(" %+f*X%d", a[j], j);
}
printf(" =%f\n", b);
}
}
void testsolve(){
//test that ax=b
int i=0,j=0;
printf("\n");
for(i=0; i<N; i++){
float s = 0;
for(j=0; j<N; j++){
s += a[j]*x[j];
}
printf("%f\t%f\n", s, b);
}
}
void printresult(){
int i=0;
printf("\n");
printf("Result\n");
for(i=0; i<N; i++){
printf("X%d = %f\n", i, x);
}
}
void diagonal(){
int i, j, k;
float temp=0;
for(i=0; i<N; i++){
if(a==0){
for(j=0; j<N; j++){
if(j==i) continue;
if(a[j] !=0 && a[j]!=0){
for(k=0; k<N; k++){
temp = a[j][k];
a[j][k] = a[k];
a[k] = temp;
}
temp = b[j];
b[j] = b;
b = temp;
break;
}
}
}
}
}
void cls(){for(int i=0; i<25; i++) printf("\n");}
int _tmain(int argc, _TCHAR* argv[])
{int i=0,j=0, k=0;
cls();
do{
printf("\nInput filename: ");
scanf("%s", filename);
InFile = fopen(filename, "rt");
}while(InFile==NULL);
count_num_lines();
allocmatrix();
rewind(InFile);
//read data from file
readmatrix();
//check if there are 0 on main diagonal and exchange rows in that case
diagonal();
fclose(InFile);
printmatrix();
//process rows
for(k=0; k<N; k++){
for(i=k+1; i<N; i++){
if(a[k][k]==0){
printf("\nSolution is not exist.\n");
return 1;
}
float M = a[k] / a[k][k];
for(j=k; j<N; j++){
a[j] -= M * a[k][j];
}
b -= M*b[k];
}
}
printmatrix();
for(i=N-1; i>=0; i--){
float s = 0;
for(j = i; j<N; j++){
s = s+a[j]*x[j];
}
x = (b - s) / a;
}
InFile = fopen(fi