Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assigment 3

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <stdio.

h>
#include <stdlib.h>

#define ROWS 5
#define COLS 5

void readArray(FILE*, float[ROWS][COLS]);


void printArray(float[ROWS][COLS]);
void uptrai(float[ROWS][COLS]);

int main(){
FILE *fptr1;
float a1[ROWS][COLS],j,n;

fptr1=fopen("array1.tex","r");
if(fptr1==NULL){printf("file not opened...");return 0;}

readArray(fptr1, a1);
printArray(a1);
printf("Multiplication Factor:\n");
uptrai(a1);
printf("\n");
printf("Lower Triangular Matrix:\n");
printArray(a1);

return 0;
}
void readArray(FILE* fptr, float a[ROWS][COLS]){
int i,j;
float k[COLS];

for(i=0;i<ROWS;++i){
for(j=0;j<COLS;++j){
fscanf(fptr,"%f ",&k[j]);
a[i][j]=k[j];
}
}
return;
}
void printArray(float a[ROWS][COLS]){
int j,i;
for(i=0;i<ROWS;++i){
for(j=0;j<COLS;++j){
printf("%f ",a[i][j]);
}
printf("\n");
}
return;
}

void uptrai(float a[ROWS][COLS]){


int i,j,k;
float mf,m;
for (i=0; i<ROWS; i++){
for (j=i+1; j<COLS; j++)
{
mf = -(a[i][i]/(a[j][i]+5*10e-10));
printf("%f ",mf);
for (k=0; k<ROWS; k++)
{
a[j][k] = mf*(a[j][k])+(a[i][k]);
}
}
}
return;
}

You might also like