C Programming - Library Functions - Discussion
Discussion Forum : Library Functions - Find Output of Program (Q.No. 7)
7.
What will function gcvt() do?
Answer: Option
Explanation:
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
Discussion:
3 comments Page 1 of 1.
Tom said:
7 years ago
Why num in scientific notation (num = 0.678e5) is printed as string = 67800?
Laasya said:
7 years ago
0.678e5 is nothing but 0.678*10^5.
So the output string is 67800.
So the output string is 67800.
Adit said:
7 years ago
Does gcvt() same as the ftoa()?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers