Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my program not returning value after the decimal?

This is the code in C :

#include <stdio.h>
#define PI 3.142857
int area(float);
int main(int argc, char const *argv[])
{
    float b,c;
    printf("Enter the radius of the circle: ");
    scanf("%f",&b);
    c =area(b);
    printf("The area of the circle is : %f",c);
    return 0;
}
int area(float r){
    float a;
    a = PI * r *  r;
    return a;
}

For example if I write the input as 3 , it should display 28.26 but is displaying the output as 28.000000.
What is wrong in the code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Return float instead of int

float area(float r){
    float a;
    a = PI * r *  r;
    return a;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading