Library Functions

Q1:

What will function gcvt() do?

A Convert vector to integer value

B Convert floating-point number to a string

C Convert 2D array in to 1D array.

D Covert multi Dimensional array to 1D array

ANS:B - Convert floating-point number to a string

The gcvt() function converts a floating-point number to a string. It converts given value to a null-terminated string.


#include <stdlib.h>
#include <stdio.h>

int main(void)
{
	char str[25];
	double num;
	int sig = 5; /* significant digits */

	/* a regular number */
	num = 9.876;
	gcvt(num, sig, str);
	printf("string = %s\n", str);

	/* a negative number */
	num = -123.4567;
	gcvt(num, sig, str);
	printf("string = %s\n", str);

	/* scientific notation */
	num = 0.678e5;
	gcvt(num, sig, str);
	printf("string = %s\n", str);

	return(0);
}
Output:
string = 9.876
string = -123.46
string = 67800



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.