Using C constant
Program to demonstrate constant
We will write a program to calculate area of circle using constant value for pi#include<stdio.h>
const float pi= 3.14; // const value of pi that will never change
void main()
{
float area=1.0,radius=1.0; // variables require for calculation
clrscr(); // removing garbage of screen
printf("Enter radius:"); // ask for radius value
scanf("%f",&radius); // accept radius
area=pi*radius*radius; // calculate area
printf("\n area = %f ",area);// display result
getch(); // hold screen until user press any key
}
Output :
0 comments:
Post a Comment