Originally Posted by

**Adak**
You tried this with doubles yet?

Some numbers will be approximations, but they're close.

Thanks for your reply, , but definitely, I don't understand what you meant.

The idea is : I could input my number with "/" and directly calculated.

Okay, actually I'm building a program for gaussian elimination. And User can input by fraction number, not round number...

Maybe, I should share to you guys my gaussian program. I just want to input my number by fraction number such as "1/2", "1/3", "1/4"...etc, and on the screen will automatically show the input become "0,50", "0,33", "0,25"...My question is "How to create it happens?", Thanks for your help guys....Actually my matrix has used double.

Code:

#include <stdio.h>
#include <math.h>
#define NMAX 100
int main()
{
int m,n; //rows and columns
int i,j,k; //help character
double A[NMAX][NMAX]; //matrix input
double x[NMAX][1]; //matrix solved
double b[NMAX][1]; //matrix output
/**********************/
/* [A][x]=[b] */
/**********************/
double pivot; //pivot element
/*Input First****************************************************************************************/
printf("This is a Gaussian Elimination program \nthat can only solve linier problem\n[A][x]=[b] ");
printf("Enter Input Matrix [A] Size Dimension (m,n) :\n");
printf("Amount of Rows:\n");
scanf ("%d",&m);
printf("Amount of Colums:\n");
scanf ("%d",&n);
if (m>100 || n>100)
{
printf("Matrix Size A is more than 100.\n");
getch();
exit(1);
}
//Enter Input for A matrix
printf("Enter Input Number for [A] matrix:\n");
for (i=0;i<m;i++)
{
printf("new row:\n");
for (j=0;j<n;j++)
{
scanf("%lf",&A[i][j]); //Input number
}
}
//Let to display the matrix input A
printf("\nYour [A] Matrix:\n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf(" %.4f", A[i][j]);
}
printf("\n");
}
//Enter input for b Matrix
printf("\nEnter Input Number for [b] matrix:\n");
printf("only one column:\n");
for (i=0;i<m;i++)
{
scanf("%lf",&b[i][0]); //Input number
}
//Let to display the matrix output b
printf("\nYour [b] Matrix:\n");
for (i=0;i<m;i++)
{
printf(" %.4f", b[i][0]);
printf("\n");
}
/*********************************************Input Finished**************************/
/*********************************************Start to Elimination********************/
/*Gaussian will be applied************************************************************/
for (j=0;j<n;j++)
{
for (i=j;i<m;i++)
{
pivot=A[i+1][j]/A[j][j];
b[i+1][0]=b[i+1][0]-(pivot*b[j][0]); //Each element of b
for(k=j;k<n;k++)
{
A[i+1][k]=A[i+1][k]-(pivot*A[j][k]); //Each element of A
}
}
}
//Show result matrix after elemination
printf("\nAfter Elimination*************\n");
printf("Your [A] Matrix:\n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf(" %.4f", A[i][j]);
}
printf("\n");
}
printf("\nYour [b] Matrix:\n");
for (i=0;i<m;i++)
{
printf("%.4f", b[i][0]);
printf("\n");
}
/********************************************End Elimination**************************/
/*Show the result*********************************************************************/
x[m-1][0]=b[m-1][0]/A[m-1][n-1]; //x(m,n) result
for (i=m-2;i>=0;i--)
{
x[i][0]=b[i][0];
for (j=m-1;j>=i+1;j--)
{
x[i][0]=x[i][0]-(x[j][0]*A[i][j]);
}
x[i][0]=x[i][0]/A[i][i];
}
//Show result matrix after elemination
printf("\nAfter Substitution*************\n");
printf("Your [X] Matrix:\n");
for (i=0;i<m;i++)
{
printf("%.4f", x[i][0]);
printf("\n");
}
/********************************************End Show*********************************/
getch();
return 0;
}

I programmed it by Dev-C++, This program definitely succeeded, but I just want to change the input by fraction number. And now I stuck with my problem.

Regards,