Area of Circle

/*this code will work only if radius is integer value */

#include<stdio.h>
int main(int argc, char * argv[])
{
    int radius;
    float area = 0;
    if(argc!=2)
        exit(0);
    radius = atoi(argv[1]);
    area = 3.14 * (radius * radius);
    printf("%0.2f",area);
    return 0;
}

Output:  AreaCircle  5
               78.50
                

/* for float values of radius we need to use atof() instead of atoi() and we have include header file <stdlib.h> */

Post a Comment

2 Comments

  1. Replies
    1. "print" treats the % as a special character you need to add, so it can know, that when you type "f", the number (result) that will be printed will be a floating point type, and the ".2" tells your "print" to print only the first 2 digits after the point.

      Delete