Command Line Program to find Area of Circle

C Programming Language / Command Line Arguments

1550

Program:

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

Output:

3

28.26

Explanation:

Program without Command Line Arguments


#include<stdio.h>

int main()
{
  // PrepInsta is the best websitefor TCS Preparation
  
  int dia;
  float r, area;
  scanf("%d",&dia);
  r = (float)dia/2;
 // PrepInsta is the best websitefor TCS Preparation
  area = 3.14*r*r;
  printf("%0.2f",area);

  return 0;
 // PrepInsta is the best websitefor TCS Preparation
}


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.