『壹』 如何用C++語言輸出一個圓的形狀
正數敗在學c語言正好從網上看到一個#include<iostream>#include<windows.h>#include<conio.h>usingnamespacestd;intmain(intargc,char*argv[]){chararg[200]={0};arg[0]='\"';strcpy(arg+1,argv[0]);intlen=int(strlen(arg));arg[len]='\"';HWNDhWnd=FindWindow(NULL,arg);//找到程序運行窗口的句柄HDChDC=GetDC(hWnd);//通過窗口句柄得到該窗口的設備場境句柄HPENhPen,hOldPen;//畫筆hPen=CreatePen(PS_SOLID,2,0x00ff00);//生成綠色畫筆hOldPen=(HPEN)SelectObject(hDC,hPen);//把畫筆引入設備場境Arc(hDC,100,100,300,300,350,500,350,500);//畫圓SelectObject(hDC,hOldPen);cout<<"畫圓形:"薯畝顫耐租<<endl;getch();return0;}
『貳』 怎麼用C語言畫一個圓形急~
#include<stdio.h>
#include<math.h>
int main()
{
double y;
int x,m;
for(y=10;y>=-10;y–)
{
m=2.5*sqrt(100-y*y); /*計算行y對應的列坐標m,2.5是屏幕縱橫比調節系數因為屏幕的
行距大於列距,不進行調節顯示出來的將是橢圓*/
for(x=1;x<30-m;x++) printf(" "); /*圖形左側空白控制*/
printf("*"); /*圓的左側*/
for(;x<30+m;x++) printf(" "); /*圖形的空心部分控制*/
printf("*\n"); /*圓的右側*/
}
return 0;
}
『叄』 用C語言寫出畫一個圓形的代碼
可以參考下面的代碼:
#include<math.h>
main()
{
double y;
int x,m;
for(y=10;y>=-10;y--)
{
m=2.5*sqrt(100-y*y);
for(x=1;x<50-m;x++)
printf(" ");
printf("*");
for(;x<50+m;x++)
printf(" ");
printf("* ");
}
}
(3)c語言編程圓形狀擴展閱讀:
for循表達式為:for(單次表達式;條件表達式;末尾循環體){中間循環體;}。
其中,表示式皆可以省略,但分號不可省略,因為「;」可以代表一個空語句,省略了之後語句減少,即為語句格式發生變化,則編譯器不能識別而無法進行編譯。for循環小括弧里第一個「;」號前為一個為不參與循環的單次表達式。
『肆』 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("*
");
}
}
『伍』 怎樣用c語言畫一個圓可以訪問graphics.h庫!circle函數怎樣用
graphics.h 是 tc 下的,vc 下你安裝了 easyx 也就有了,然後畫圓這樣:
#include <graphics.h> // 引用圖形庫
#include <conio.h>
void main()
{
initgraph(640, 480); // 初始化圖形窗口
circle(100, 100, 60); // 畫圓,圓心(100, 100),半徑 60
getch(); // 按任意鍵繼續
closegraph(); // 關閉圖形界面
}
『陸』 急求C語言中怎樣畫一個圓形圖形
#include<stdlib.h>
#include<graphics.h>
int main()
{
int gdriver, gmode, i;
gdriver=DETECT;
initgraph(&gdriver, &gmode, "c:\\caic\\bgi");
setbkcolor(BLUE);/*設背景顏色*/
cleardevice();
setcolor(12); /*設置作圖顏色*/
arc(100, 100, 0, 360, 50); /*畫一個以(100,100)為圓心,50為半徑,從0度到360度的圓*/
getch();
closegraph();
return 0;
}
/*turbo c2.0下編譯通過*/
『柒』 如何用C語言程序來設計一個圓的MFC圖案
如果是圓形對話框,則按照以下思路:
1、取掉對話框的邊框;2、將對話框背景色設置成你的點陣圖(因為對話框背景色要求點陣圖為方形,可以將圓形以外的用一種不用的色值填充,一般用FF00FF);3、用SetLayeredWindowAttributes()設置對話框的過濾色值(第二值中所說的圓形以外的色值)即可。注意這時候對話框必須具有WS_EX_LAYERED屬性
『捌』 怎麼用c語言畫出一個隨時間變化的圓形
circle函數是TURBO C提供的圖形介面,用來畫圓。不屬於標准庫函數,不具備可移植性。
函數名:circle
功 能: 在給定半徑以(x, y)為圓心畫圓
用 法:void far circle(int x, int y, int radius)隨時間變化,可以攜此用cleardevice函數清除屏幕,不斷畫半徑不同的圓。看起來就像是一個隨時間變化的圓形。
函數名: cleardevice
功 能: 清除圖形屏幕
用 法: void far cleardevice(void);
常式:#include<graphics.h>
#include<stdlib.h>指改
#include<stdio.h>
#include<conio.h>
intmain(void)
{
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
intmidx,midy;
intradius=100;
/**/
initgraph(&gdriver,&gmode,"");
/*readresultofinitialization*/
errorcode=graphresult();
if(errorcode!=grOk)/*anerroroccurred*/
{
printf("Graphicserror:%s ",grapherrormsg(errorcode));
printf("Pressanykeytohalt:");
getch();
exit(1);/*terminatewithanerrorcode*/
}
midx=getmaxx()/2;
midy=getmaxy()/2;
setcolor(getmaxcolor());
for(i=0;i<1000000;i++)if(i%50000==0){
辯逗迅cleardevice();/*cleanthescreen*/
circle(midx,midy,radius--);/*drawthecircle*/
}
getch();
closegraph();
return0;
}
『玖』 如何利用c語言程序設計繪制一個形狀(圓,橢圓,矩形都可以),用線條動態地填充其內部
你的c 編譯器需帶 繪圖函數庫 才行。
c++ API 程序 可以繪圖。只要得到窗口句柄,就可在該窗畫圖。畫直線,多邊形,圓,橢圓,扇形 等 都是基本函數。
下面程序在桌面窗口畫線:
#include <Afxwin.h>
#include <Windows.h>
#pragma comment (lib, "User32.lib")
int main(void){
HWND hWnd = ::GetDesktopWindow();
HDC hdc = ::GetDC(hWnd);
// HDC hdc = ::GetDC(NULL);
RECT rect;
::GetWindowRect(hWnd, &rect);
::MoveToEx(hdc, 0, 0, NULL);
::LineTo(hdc, rect.right, rect.bottom);
::MoveToEx(hdc, rect.right, 0, NULL);
::LineTo(hdc, 0, rect.bottom);
::ReleaseDC(hWnd, hdc);
system("PAUSE");
return 0;
}
===
用「刷子」畫填充的封閉圖形 (參數是 花紋,顏色)
HBRUSH Brush[5];
case WM_PAINT:
Brush[0] = CreateHatchBrush(HS_BDIAGONAL, RGB(0, 0, 255));
Brush[1] = CreateHatchBrush(HS_CROSS, RGB(200, 0, 0));
Brush[2] = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 128, 0));
Brush[3] = CreateHatchBrush(HS_FDIAGONAL, RGB(0, 128, 192));
Brush[4] = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 128, 0));
----
編譯器 MS VC++ 6.0.
API 程序羅嗦,這里就不列出來了。
『拾』 怎樣用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;
}