WAP- Given the radius of a circle, write a program to compute and display its area. Use a symbolic constant to define the pi value and assume a suitable value for radius

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.5, page 21

#include <stdio.h>

#define PI 3.142

int main(void)
{float radius,area;

printf("\n\n");

printf("Enter radius of circle : ");
scanf("%f",&radius);

area=PI*radius*radius;

printf("Area of circle : %f",area);

printf("\n\n");
return 0;
}

Comments

  1. thank u .... so much ... i need some other questions answer tooo .. of E.balagusamy ANSI C 4e book...where can i get the answers of the exersice...

    ReplyDelete
  2. Hi

    Try to search the Net. I'll also put them up when I complete them.

    Warm regards
    Gopal

    ReplyDelete
  3. Replies
    1. #define PI 3.142 is a symbolic constant, where we assign a value to a name which cannot be changed later.

      Wherever we want to use the original value, we use the name as defined e.g. PI

      This helps to prevent accidental modification of an important value, and provides it a name to easily identify what the value means (and thus avoid magic numbers)

      Delete
  4. Can we use only main function in place of int main (void).

    ReplyDelete

Post a Comment

Kindly keep your comments on-topic and don't spam.