Saturday, 25 February 2017

GATE EXAM PREPARATION IN "C" - What is the best way in C to convert a number to a string?

Solution: Use sprintf() function.

#include<stdio.h>
int main()
{
    char result[50];
    float num = 23.34;
    sprintf(result, "%f", num);
    printf("\n The string for the num is %s", result);
    getchar();
}

No comments:

Post a Comment