## 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: 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. 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.

Example: ``````Input: 5
Area of circle = pi * r2 = 3.14 * (5)2   = 3.14 * 25 = 78.5
Output = 78.5

## Pre-requisites:

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.

## Program

### C program to find area of circle

``````#include<stdio.h>
int main()
{
int radius_of_circle; //declare variable to accept user input
float area_of_circle; //declare variable to store output value
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;
}
``````

### Output

``````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.

## C program to swap two numbers using bitwise operators

``````#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
printf("n Enter values for a and b:");
scanf("%d%d",&a,&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");
printf("a=%d,b=%d\n",a,b);
getch();
}

``````

output:

``````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

``````#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
char str;
printf("n Enter any string:");
scanf("%s",&str);
while(str[i]!='')
{
printf("character = %ct",str[i]);
}
getch();
}
``````

Ouput:

``````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

``````

## prime numbers:

prime numbers are divisible by only 1 and that number itself. Eg.in this program, as per divisions, integer number 5 can be divided by 1 and integer number 5 which is nothing but original number so it is prime number. 2 is the only even prime number.
prime number:2,3,5,7,11,13,17,19,23,29,…

## logic:

Below program to find prime number takes user input and then if condition inside for loop checks whether number is divisible by smaller number than input number which is 1 or number itself.

``````#include<stdio.h>
#include<conio.h>
#include<math.h>
void printprimes();
int checkprimes(int num);
void main()
{
int i;
int flag;
printf("\n Prime numbers from 1 to 100:");
printprimes();
getch();
}
void printprimes()
{
int i,j;
for(i=2;i<=100;i++)
{
if(checkprimes(i));
printf("%d\t",i);
}
}
int checkprimes(int num)
{
int j;
for(j=2;j<=sqrt(num);j++)
{
if(num%j==0)
return 0;
}
return 1;
}
``````

Ouput:

``````  ```Similar programs:
You might also like to see:```

Program to find prime number using function

## Define palindrome number:

When we reverse digits of number from right to left, then number can be seen as similar number it was previously then it is called palindrome number.
Example: suppose number considered is 121 and after we do reversal then digits of this number still stay same, so that 121 is palindrome number

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int val;
printf("n Enter a number: ");
scanf("%d",&val);
if(val==palindrome(val))
{
printf("\n %d is a palindrome no",val);
}
else
{
printf("\n %d is not a palindrome no",val);
}
getch();
}

int palindrome(int val)
{
if(val)
{
remain=val%10;
rever=rever*10+remain;
palindrome(val/10);
}
return rever;
}
``````

Ouput:

``````Enter a number: 16461
16461 is a palindrome no

``````

## Define Palindrome number:

Palindrome number is viewed with same value after we do reversal of its digits.
Example: Say number is, number = 212, then reversal of its digits will make output be like number = 212. so that here 212 is a palindrome.

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int val;
printf("\n Enter a number: ");
scanf("%d",&val);
if(val==palindrome(val))
{
printf("\n %d is a palindrome",val);
}
else
{
printf("\n %d is not a palindrome",val);
}
getch();
}
int palindrome(int val)
{
for(;val>0;val=val/10)
{
remain=val%10;
rever=rever*10+remain;
}
return rever;
}
``````

Ouput:

``````Enter a number: 212
212 is a palindrome
``````

## Palindrome number:

It is an integer number that stays same after reversal of its digits.
Example: say value of integer is, N = 121, then output will be 121. So that value 121 is called palindrome.

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int num;
printf("\n Enter a number: ");
scanf("%d",&val);
if(val==palindrome(val))
{
printf("\n %d is a palindrome",val);
}
else
{
printf("\n %d is not a palindrome",val);
}
getch();
}
int palindrome(int val)
{
do
{
remain=val%10;
rever=rever*10+remain;
val=val/10;
}while(val>0);
return rever;
}
``````

Ouput:

``````Enter a number: 12121
12121 is a palindrome
``````

## Palindrome number is:

It is an integer that has same value even after the reversal of its digits.
Example: say the input, Number = 12121, after reversal is done,then Number = 12121. So that 12121 is called palindrome.

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int num;
printf("\nEnter a number: ");
scanf("\n%d",&val);
if(val==palindrome(val))
{
printf("\n%d is a palindrome no",val);
}
else
{
printf("\n%d is not a palindrome no",val);
}
getch();
}
int palindrome(int val)
{
while(val)
{
remain=val%10;
rever=rever*10+remain;
val=val/10;
}
return rever;
}
``````

Ouput:

``````Enter a number: 12321
12321 is a palindrome no
``````
error: Content is protected !!