Sunday, August 7, 2011

Chapter 1, exercise 2

2.  What does this program do?


#include <stdio.h>


int radius, area;


int main(void)
{
  printf("Enter radius : ");
  scanf("%d", &radius);
  area = (int) 3.14159*radius*radius;
  printf("\n\nArea=%d\n", area);
  return 0;
}

This program prompts the user to enter a number, representing the radius of a circle.  It then calculates the area of the circle as an integer and prints that area to the standard output, then exits normally.

No comments:

Post a Comment