The function takes a pointer to an array of char elements that need to be converted, and a format string needs to be written in a buffer as a string
int sprintf(char *str, const char *format, ...)
#include<stdio.h>
#include <math.h>
int main()
{
char str[80];
sprintf(str, "The value of PI = %f", M_PI);
puts(str);
return 0;
}
The output after running the above code:
Output: Value of Pi = 3.141593