Defining Named Constants with #define - C Language Basics

C examples for Language Basics:Constant

Description

Defining Named Constants with #define

Demo Code

#include <stdio.h>
#define PI   3.14159f                       // Definition of the symbol PI

int main(void){
  float radius = 0.0f;
  float diameter = 0.0f;
  float circumference = 0.0f;
  float area = 0.0f;

  printf("Input the diameter of a circle:");
  scanf("%f", &diameter);

  radius = diameter/2.0f;//from  w ww .ja  va  2s.c  o m
  circumference = 2.0f*PI*radius;
  area = PI*radius*radius;

  printf("\nThe circumference is %.2f. ", circumference);
  printf("\nThe area is %.2f.\n", area);
  return 0;
}

Related Tutorials