C program to find area of circle

In this program, we are going to find area of circle using given formulas and implement it through c language.
First, we will see concepts:

Area of circle:

area of circle
All area inside circle in filled with light blue colour is area of circle. To find out the area of circle value, standard formula used is:
Area of circle = pi * (r)2

Here, pi is constant whose standard value is 3.14 and r is radius of circle.

circle radius

As you can see in figure, half line in circle depicts the radius of circle. This is brief to our concepts that we are going to learn in this program.
Now, to implement above formula in c program, we need to use PI constant in our program and radius, we can input that through command i.e. user input.



Input: 5
Area of circle = pi * r2 = 3.14 * (5)2   = 3.14 * 25 = 78.5
Output = 78.5
So, answer is 78.5


To be able to write this program, knowledge of basics, c program structure, main method, data types and variables, input output function is necessary. These are basic concepts which are implemented almost in every program.

Important for this program:

Input/output function to accept and print output, main method for program execution, variables to store values and data types to declare variable type.

Step by step approach:

  • First, define constant pi before main function. Then create variable radius to store radius of circle which will be then used in area of circle formula.
  • Second, declare float variable, area of circle, to store the resulting output value from calculation. We can either use float or long data type while declaring it depending upon range of input value. If input value is large number (two digit or three digit), we need to declare as long type for output variable (area of circle).
  • Third, display output value using printf function.

Here, \n is used in program to move cursor to new line after each input output statement. It is also called as escape sequence character.


C program to find area of circle

int main()
  int radius_of_circle; //declare variable to accept user input
  float area_of_circle; //declare variable to store output value
  printf("\n Enter the circle radius:");
  scanf("%d",&radius_of_circle); // accept user input
  area_of_circle = pi * radius_of_circle * radius_of_circle; // calculate area of circle
  printf("\n Area of circle will be %f", area_of_circle); //  display are of circle
  return 0; 


Enter the circle radius: 5
Area of circle will be 78.500000

Program Explanation:

In this program, we have used standard formula to calculate area of circle. Formula uses pi constant so that we have defined pi as constant and set it value 3.14 before main method begins.

#define pi 3.14


We have declared two variables to store input (radius_of_circle) and display output (area_of_circle) respectively. Here in this program, we have used integer data type while declaring radius variable because we have entered integer input in the program example. So if you want to input any floating value then float variable is mandatory otherwise output will be inaccurate.

Variable, area_of_circle is declared of float data type because output value will be decimal value/floating value. If input is large number then we can declare area_of_circle variable as long data type because it can hold larger floating value.

After calculation of area of circle, area_of_circle = pi * radius_of_circle * radius_of_circle;
We have displayed the output value using printf function at end of program and then return 0 statement added to return 0 value indicating successful program execution of main method.

If you have any doubt leave comment below post.

Keep coding.

Download Turbo C++ for Windows 7, 8 32 bit/64 bit Operating System

You can download the compiler from provided link below. For Beginners who are first time running the application below is quick overview.
How you can install Turbo C++ compiler on windows 7, 8 ?

Step 1 Download Turbo C++
Step 2 Run “setup.exe” file
Step 3 start or run the program by clicking Windows Key then search Turbo C++ or click on Turbo C++ shortcut on Desktop

Note: When you start Turbo C++ compiler it will open in Full mode. Click Alt + Enter key combination to return to minimize window.

Link to download : Click Here to Download Turbo C++

For downloading the application wait for 5 seconds and and click on skip then application will be downloaded automatically.

C program to swap two numbers using bitwise operators

void main()
 int a, b;
 printf("n Enter values for a and b:");
 printf("Before swapping: n");
 printf("a=%d, b=%d\n",a,b);
 a = a^b;
 b = a^b;
 a = a^b;
 printf("After swapping: n");


Enter values for a and b: 10 20
Before swapping:
a=10, b=20
After swapping:
a=20, b=10

C program to print characters in a string and address of each character

void main()
   int i=0;
   char str[10];
   printf("n Enter any string:");
     printf("character = %ct",str[i]);
     printf("address = %pn",&str[i]);


Enter a string: clessons
character = c   address = FFEC
character = l   address = FFED
character = e   address = FFEE
character = s   address = FFEF
character = s   address = FFF0
character = o   address = FFF1
character = n   address = FFF2
character = s   address = FFF3

Program to find range of different data types in C

ranges of various data types

Data type ranges specifies maximum value and minimum value which can be stored inside a variable of given data type. These data types can be used only when header files are included in program.

Below are the symbolic constants defined in header file which returns max and min limit for specific type of data.

Constants, data types predefined in   header file:

    • INT_MIN: This constant return min value of type integer (-32768)
    • INT_MAX: This constant return max value of type integer (32767)
    • UINT_MAX: This constant return max value of type unsigned integer (65535)
    • SHRT_MIN: This constant return min value of type short (-32768)
    • SHRT_MAX: This constant return max value of type short (32767)
    • USHRT_MAX: This constant return max value of unsigned short (65535)
    • LONG_MIN: This constant return min value of type long (-2147483648)
    • LONG_MAX: This constant return max value of type long (2147483647)
    • ULONG_MAX: This constant return max value of type long (4294967295)
    • CHAR_MIN: This constant return min value of type char regardless of whether type is signed or unsigned by default (-128)
    • CHAR_MAX: This constant return max value of type char regardless of whether type is signed or unsigned by default (127)
    • SCHAR_MIN: This constant return min value of type char (-128)
    • SCHAR_MAX: This constant return max value of type char (127)
    • UCHAR_MAX: This constant return max value of unsigned char (255)

Program to find range of int, char, short int, long int, etc types





Output of program shows minimum and maximum value held by any data type. It includes range of int, short int, long int, char, unsigned char types etc.

error: Content is protected !!