Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am a beginner to coding.I have to find the area of a circle using c ,I wrote the code but I run it it shows 'undefined reference to main'.Please explain what I'm doing wrong

What I have tried:

#include <stdio.h>

float area(float r)
    float area;
    printf("\nEnter the radius of Circle : ");
    scanf("%f", &r);
    area = 3.14 * r * r;
    printf("\nArea of Circle : %f", area);

    return area;
Updated 20-Jun-23 22:56pm

Every program has what is called an "entry point" - a place in the code that the system "knows" will start the application.

It's kind of like a book - when you start reading it, you begin at the first page of text: the introduction or chapter 1, depending.

For a C console app, it's a function called main
So add this below the area function:
int main()
   float r = 0.0f;
   float f = area(f);
   return 0;
Share this answer
Every C program must have a main function. It is the entry point of the program.

Refer to this How to write a good C main function |[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900