Language%20in%20C%20Interview%20Questions%20and%20Answers
Question: How do I use function ecvt( ) in a program?
Answer: The function ecvt( ) converts a floating-point value to a null terminated string. This function takes four arguments, such as, the value to be converted to string, the number of digits to be converted to string, and two integer pointers. The two-integer pointer stores the position of the decimal point (relative to the string) and the sign of the number, respectively. If the value in a variable, used to store sign is 0, then the number is positive and, if it is non-zero, then the number is negative. The function returns a pointer to the string containing digits. Following program demonstrates the use of this function.#include <stdlib.h> main( ) { char *str ; double val ; int dec, sign ; int ndig = 4 ; val = 22 ; str = ecvt ( val, ndig, &dec, &sign ) ; printf ( "string = %s dec = %d sign = %dn", str, dec, sign ) ; val = -345.67 ; ndig = 8 ; str = ecvt ( val, ndig, &dec, &sign ) ; printf ( "string = %s dec = %d sign = %dn", str, dec, sign ) ; // number with a scientific notation val = 3.546712e5 ; ndig = 5 ; str = ecvt ( val, ndig, &dec, &sign ) ; printf ( "string = %s dec = %d sign = %dn", str, dec, sign ) ; } The output of this program would be string = 2200 dec = 2 sign = 0 string = 34567000 dec = 3 sign = 1 string = 35467 dec = 6 sign = 0 |
Is it helpful?
Yes
No
Most helpful rated by users:
- What will be the output of the following code?
void main ()
{ int i = 0 , a[3] ;
a[i] = i++;
printf ("%d",a[i]) ;
} - Why doesn't the following code give the desired result?
int x = 3000, y = 2000 ;
long int z = x * y ; - Why doesn't the following statement work?
char str[ ] = "Hello" ;
strcat ( str, '!' ) ; - How do I know how many elements an array can hold?
- How do I compare character data stored at two different memory locations?