In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to draw a circle in C language. The editor thinks it is very practical, so I hope you can get something after reading this article. Let's take a look at it with the editor.
I. concept description 1.1 Circle
In a plane, a closed curve formed by rotating a circle around a point at a distance of a certain length is called a Circle.
The expression of the circle: (x-a) ²+ (y-b) ²= r ²
In the case of: X ²+ y ²= r ²
1.2 Circle pattern
For reference and understanding only:
Second, the problem presents 1. Problem description
Problem Description:
Draw a hollow circle on the screen with the character "*".
two。 Input and output
Input
None
Output
Display a hollow circle with the character "*"
3. Test sample
Sample Input
None
Sample Output
3. Source code implementation (+ comments) # include#include#include / / defines the mathematical function library because the sqrt function int main () {double y; int x Magi m; for (y = 10 X y > =-10) is used ) {/ / the radius of the circle is 10 / / the column coordinates corresponding to calculation y m2.03 is the screen aspect ratio adjustment factor m = 2.03 * sqrt (100-y*y); / / because the row spacing of the screen is greater than the column spacing, the ellipse for (x = 1position x) will be displayed without adjustment.
< 30-m; x++) printf(" "); //图形左侧空白控制 printf("*"); //左半圆 for( ;x < 30+m; x++) printf(" ");//图形空心部分控制 printf("*\n");//圆的右侧 }}四、输出结果图示 五、简要解释1.实现关键 关键在于在屏幕上用" * " 画一个空心的圆。 我们输出圆可利用图形的左右对称性。 根据圆的方程: x * x + y * y = r * r 可以计算出圆上每一点行和列的对应关系。 2.小说明 m = 2.03 * sqrt(100 - y * y); ① y就是圆的方程中的y ② y对应的列坐标m ③2.03是屏幕纵横比调节系数 为什么要调节屏幕纵横比 ? 因为在电脑上,一般都是行距大于列距,例如可以联系常见的屏幕分辨率1920x1080 1920>1080 to understand.
④ sqrt is the square function in the math mathematical function library.
What is C language? C language is a process-oriented and abstract general programming language, which is widely used in low-level development. C language can be used to compile and process low-level memory in a simple way.
The above is how to draw a circle in C language. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.