Square Root of Prime Number using Command Line Argument

C Programming Language Command Line Arguments (Article) Command Line Arguments (Program)

791

Program:

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
bool isPrime(int n)
{
    if(n<2)
    return false;
    
    int i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        return false;
    }
    return true;
}


int main(int argc, char *argv[])
{
    if(argc==1)
    {
        printf("No arguments");
        return 0;
    }
    else
    {
        int n;
        n=atoi(argv[1]);
        float sq=0;
        
        if(isPrime(n))
        {
            sq=sqrt(n);
            printf("%.2f",sq);
        }
        else
        printf("%.2f",sq);

    return 0;
    }
}

Output:

13

3.16

Explanation:

Nope

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.