[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Basics

Home > Programs > Basics

321 / 279

Write a program in C using command line argument, take input as diameter of circle and calculate the area of circle.

Answer:

#include 
#include 
#define PI 3.142

int main(int argc, char * argv[])
{
    float radius, area;
if(argc == 1 ||  argc > 2)
      {
            printf("Enter the diameter of circle\n");
            exit(1);
      }
    radius = atoi(argv[1]) / 2;
    area = PI * radius * radius ;
    printf("Area of a circle = %5.2f\n", area);
}

Asked In :: TCS

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: