1. c語言中關於畫圓程序
#include<stdio.h>
#include<math.h>
main()
{
double y;
int x,m;
for(y=10;y>=-10;y--) //表示圖形的第y行,通過for循環列印所有行
{
m=2.5*sqrt(100-y*y); //用y作為自變數,根據弦長與縱坐標y的函數關系計算出此行上的弦 長的一半也就是兩個星形符號之間的距離的一半,並用m表示。
for(x=1;x<50-m;x++) //以50個字元長度為基準根據弦長來確定每行左數第一個星形的位 置,此位置前全印空格
printf(" ");
printf("*");
for(;x<50+m;x++) //以50個字元寬度為基準來確定每行第二個星形的位置
printf(" ");
printf("*\n");
}
}
//此程序列印的只是個大概的圓形,因為運行輸出窗口裡,相鄰的行距和鄰字元的列距是不相等的,所以語句 m=2.5*sqrt(100-y*y);中的2.5是用來修正此誤差的。可根據具體運行平台適當修改。 如果還看不懂,再問
2. 到底要怎樣才能在C語言中輸出一個圓啊,能不能盡量簡單一點
/*在TC編譯器下運行,在VC下要添加頭文件"graphics.h"*/
#include<graphics.h>
main(){
int graphdriver=DETECT;
int graphmode;
initgraph(&graphdriver,&graphmode,"");/*初始化*/
setcolor(RED);/*設置顏色*/
circle(100,100,30);/*畫圓函數,第一個參數為圓心的橫坐標,第二個參數為縱坐標,第三個為半徑*/
getch();
closegraph();
}
3. c語言從外部輸入圓的面積,並根據此面積求圓的半徑
根據圓的面積,求圓的半徑。其圓面積公式為:S=PI*R*R,故可以編寫如下
C
語言源代碼:
#include
<stdio.h>
#include
<math.h>
/*
sqrt(
)
函數在此頭文件有定義
*/
#define
PI
3.1415926
/*
定義一個常量
PI,其值為
3.1415926
*/
void
main(
)
{
float
S,
R
;
/*
定義兩個浮點變數
S
表示圓的面積、R
表示圓的半徑
*/
printf("Please
input
a
circle
area:\n")
;
scanf("%f",
&S)
;
/*
從鍵盤上輸入圓的面積
*/
R
=
sqrt(
S/PI
)
;
/*
根據圓的面積公式
S=
PI*R*R,計算圓的半徑
R
*/
printf(
"R
=
%f\n",
R
)
;
/*
輸出圓的半徑
R
的值
*/
}
4. C語言求圓周長和面積
一、數學公式:
圓周長=2*π*半徑
面積=π*半徑²
二、演算法分析:
周長和面積都依賴半徑,所以要先輸入半徑值,然後套用公式,計算周長和面積。 最終輸出結果即可。
三、參考代碼:
代碼如下
#include"stdio.h"
#definePi3.14
voidmain()
{
floatr,c,area;
printf("請輸入圓的半徑:");
scanf("%f",&r);
c=2*Pi*r;
area=Pi*r*r;
printf("該圓的周長是%.2f,面積是%.2f ",c,area);
}
5. 輸入圓的半徑,c語言求圓的面積並顯不出來
思路:宏定義圓周率PI=3.14,鍵盤輸入半徑r,計算PI*r*r,並輸出。
參考代碼:
#include<stdio.h>
#definePI3.14
intmain()
{
floatr,s;
scanf("%f",&r);
s=r*r*PI;
printf("S=%.2f",s);
return0;
}
/*
運行結果:
10
S=314.00
*/
6. 怎樣用C語言畫圓
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
char arg[50]={0};
arg[0]= '\ " ';
strcpy(arg+1,argv[0]);
int len=int(strlen(arg));
arg[len]= '\ " ';
HWND hWnd=FindWindow(NULL,arg); //找到程序運行窗口的句柄
HDC hDC=GetDC(hWnd);//通過窗口句柄得到該窗口的設備場境句柄
HPEN hPen,hOldPen; //畫筆
int i=0;
for(;i <500;++i)
SetPixel(hDC,10+i,10+i,0x0000ff);//用畫點的辦法畫一根線,最後一個參數是顏色(32位)
hPen=CreatePen(PS_SOLID,2,0x00ff00);//生成綠色畫筆
hOldPen=(HPEN)SelectObject(hDC,hPen);//把畫筆引入設備場境
MoveToEx(hDC,20,50,NULL); //設置畫線起點
LineTo(hDC,520,550); //畫到終點
Arc(hDC,100,100,300,300,350,500,350,500);//畫圓
SelectObject(hDC,hOldPen);
ReleaseDC(hWnd,hDC);
//下面是對比,表明它確實是控制台程序
printf( "hello console ");
system( "pause ");
return 0;
}
7. 求c語言編程設計一個常用圓形體體積計算器,的設計思路
用switch語句根據用戶輸入的數字選擇對應的計算方法,假設用戶輸入用choice變數保存
switch(choice)
{
case 1: V=(float)4/3*PI*r*r*r;break;
case 2: V=PI*r*r*h;break;
case 3: V=(float)1/3*PI*r*r*h;break;
default:printf("輸入錯誤");
}
8. C語言有關圓的計算問題
還是:scanf("%.3f%d",r,h);
有問題。除了要在變數名前加&外,C還規定:輸入實型數據時,不能指定精度。只能寫成:
scanf("%f%d",&r,&h);
9. C語言 四個圓塔那題,思路是什麼我只想知道思路和其中的關系式,請幫忙……
#include<stdio.h>
#include<math.h>
constinttower_height=10;
boolis_circle_contain(doublepx,doublepy,doublecircle_x,doublecircle_y,doubleradius){
returnpow(fabs(px-circle_x),2)+pow(fabs(py-circle_y),2)<=pow(radius,2);
}
boolis_tower(doublepx,doublepy){
constintradius=1;
returnis_circle_contain(px,py,2,2,radius)
||is_circle_contain(px,py,-2,2,radius)
||is_circle_contain(px,py,2,-2,radius)
||is_circle_contain(px,py,-2,-2,radius);
}
intmain(){
doublex,y;
scanf("%lf%lf",&x,&y);
if(is_tower(x,y))
printf("%dm ",tower_height);
else
printf("0m ");
return0;
}
10. C語言怎麼畫圓
#include <math.h>#include <stdio.h>#define R 10 //半徑 #define X 10 //圓心x坐標 #define Y 10 //圓心Y坐標 int main(void)
{ int x,y; int m; int i; for(i=Y-R;i>=1;i--)
{ printf("
");
}
for(y=R;y>=-R;y--)
{
m=2*sqrt(R*R - y*y); //橫坐標的偏移量,因為字體長寬比例為2,所以要乘2
for(x=1;x<X+R-m;x++) //列印左半圓
{ printf(" ");
} printf("*"); for(;x<X+R+m;x++) //列印右半圓
{ printf(" ");
} printf("*
");
}
}