#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
main()
{
FILE *stream;
int j, i;
double A0, A1, A2;
double b01, b0, a1, a0, tempb0;
char jawab, ganda, filedata[20];
do
{
i = 1;
b0 = 0.0;
cout << "\nMetode Faktorisasi P3(x) = P(1,2)\n";
cout << "================================\n\n";
cout << "\nMasukkan nama file penyimpanan Data = ";
cin >> filedata;
stream = fopen(filedata, "w+");
cout << "\nMasukkan Nilai A2 = ";
cin >> A2;
cout << "\nMasukkan Nilai A1 = ";
cin >> A1;
cout << "\nMasukkan Nilai A0 = ";
cin >> A0;
cout <<"\nBerapa kali Iterasi = ";
cin >> j;
printf("\n\n\t---------------------------------\n");
printf("\titerasi\t b0\t a1\t a0\n");
printf("\t---------------------------------\n");
fprintf(stream,"\n\n\t---------------------------------\n");
fprintf(stream,"\titerasi\t b0\t a1\t a0\n");
fprintf(stream,"\t---------------------------------\n");
do
{
if(b0 != 0)
{
a1 = A2 - b0;
a0 = A1 - (a1*b0);
b01 = A0/a0;
if (i != j)
{
printf("\t %d\t%.3f\t%.3f\t%.3f\n", i, b01, a1, a0);
fprintf(stream,"\t %d\t%.3f\t%.3f\t%.3f\t\n", i, b01, a1,
a0);
}
else
{
break;
}
}
else
{
a1 = A2 - b0;
a0 = A1 - (a1*b0);
printf("\t %d\t%.3f\t%.3f\t%.3f\n", i, b0, a1, a0);
fprintf(stream,"\t %d\t%.3f\t%.3f\t%.3f\t\n", i, b0, a1, a0);
if (a0 != 0)
{
b01 = A0/a0;
}
else
{
break;
}
}
tempb0 = b0;
b0 = b01;
b01 = tempb0;
i++;
}while( i <= j);
printf("\t---------------------------------\n");
fprintf(stream,"\t---------------------------------\n");
if (a0 != 0)
{
do
{
} while(ganda != 't');
}
else
{
printf("\n\na0 = %.2f not valid (error floating point)\n\n", a0);
}
} while(jawab != 't');
fclose(stream);
return 0;
}
Tidak ada komentar:
Posting Komentar