Printing float pi using C language.
Printing the value of pi as a float variable in the C language is an
important skill for any programmer. In this blog post, we will explore the
different ways to print the value of pi as a float variable in C, including the
use of the printf function and format specifiers. Whether you
are a beginner or an experienced programmer, this post will provide valuable
insights and tips on how to effectively print the value of pi as a float
variable in your C programs.
#include<stdio.h>
int main() {
float pi = 3.14;
printf("Number is %f\n", pi);
return 0;
}
This is a simple C program
that prints the value of a float variable to the standard output. Here is an
explanation of each line of the code:
- #include<stdio.h>: This line includes
the stdio.h header file,
which contains the declarations for the printf function used in the program.
- int main() {: This line defines
the main function,
which is the entry point of the program.
- float pi = 3.14;: This line declares
a float variable named pi and initializes it with the value 3.14.
- printf("Number is %f\n", pi);: This line calls
the printf function to
print the string "Number is " followed by the value of the pi variable, followed by a newline
character (\n) to the standard
output. The %f format
specifier is used to print the value of the pi variable as a float.
- return 0;: This line returns 0 from the main function, indicating that the program
has executed successfully.
- }: This line marks the end of the main function.
My YouTube Channel ::
Thanks for visiting my Blog. Hopefully it helped you. Please check out more blogs for practice.
We will meet soon. bye. Jay Hind...
Comments
Post a Comment