1709403739

Creating a program that calculates the area and circumference of a circle with C


Programming code of the solution ```c #include <stdio.h> #define PI 3.14 int main(){ int rad; float area, circum; printf("Enter radius of a circle in cm: "); scanf("%d", &rad); area = PI*rad*rad; circum = 2*PI*rad; printf("Area of the circle = %0.2f\n", area); printf("Circumference of the circle = %0.2f", circum); return 0; } ``` **input and output of the executed program:** ``` Enter radius of circle in cm: 3.4 Area of the circle = 28.26 Circumference of the circle = 18.88 ``` This was a demonstration of how we can calculate the area and circumference of a circle implemented in the C language. In the next post, I'll show you how to calculate the power of a given number. If you liked this post, leave a comment. Thank you

(2) Comments
JavaJuggler
JavaJuggler
0

thanks for the tip friend @Awschult, I will continue to post some more things about C and Cplusplus and all criticism and suggestions will be welcome for better learning.


Awschult
Awschult
0

Nice post!I have a couple of recommendations. Depending on what level of "professionalism" you want to teach, I would consider using `puts()` instead of `printf()` for string that don't need formatting as it is safer and more performant. Also, the standard math library has a `PI` constant built-in that is more accurate.


Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2024 © Chat-to.dev]