Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed I need to use the number pi in C. How to enter it?

+3 votes
asked Nov 17, 2021 by xRikishi (150 points)
closed Nov 25, 2021 by Admin
for example y=pi*4?
closed with the note: answered

2 Answers

+3 votes
answered Nov 19, 2021 by Peter Minarik (84,720 points)

Well, you know the value of PI, all you have to do is create either a variable or a macro for it.

#include <stdio.h>

#define PI 3.14159265359f
// float PI = 3.14159265359f; // This would work just as fine

int main()
{
    float y = PI * 4.0f;
    printf("y = %f\n", y);
    return 0;
}
commented Nov 19, 2021 by YOU AINT A HACKERR MF (100 points)
i agree with you since you declared the value of PI as a global var it can be used anywhere in the prorgram
+1 vote
answered Nov 24, 2021 by Tg-Tycoon (160 points)

You can also use it directly by adding another library in your code. 

The library is math.h, I will demonstrate it by calculating area of a circle, so it would look like,

#include<stdio.h>

#include<math.h>

int main()

{

      float r;

      printf("Enter the value of radius of circle\n");

      scanf("%f",&r);

      printf("The area of the circle is %f\n",M_PI*r*r);

      return 0;

}

      Hope it helps

              smiley

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...