In scanf() function I want to take only upto decimal values.Can we achieve it?
For example for displaying upto two decimal places we use printf(\"%.2f\",
pow from math.h fails to compile, must compile with gcc file.c -o file -lmInput : 13254.45488
Output: 13254.45
void main()
{
int x,y,i ;
int precision = 2 ; /*Insert precision here*/
char a[precision] ;
long double z,result ;
printf( "Input : " );
scanf( "%d" , &x );
for ( i = 0 ; i <= precision ; i++ )
{
a[i] = getchar();
if ( a[i] == 10 ) break;
}
a[0] = '0';
a[i] = '\0';
y = atoi(a);
z = y / pow( 10 , i-1 );
result = x ;
if ( z != 0 ) result = result + z ;
printf( "Output: " );
printf( "%.*Lf\n", i-1 , result );
}