本文目錄一覽:
- 1、c語言題目鋪地毯,為什麼我的不對?急。
- 2、C語言地毯問題
- 3、用c語言畫矩形
- 4、用C語言畫矩形
- 5、C語言怎麼畫矩形??
- 6、謝爾賓斯基地毯 用c語言寫出生成代碼。 要完整的,不只是函數的代碼
c語言題目鋪地毯,為什麼我的不對?急。
程序沒有錯。
可能的問題是:不清楚地毯鋪設的最大坐標。若是超過了1999,你的程序就數組越界了。
第二,這程序的
時間複雜度
稍大了些。
可以把這些數據放入一個4*n的
二維數組
中,全部讀入數據後,從n往回檢查,若坐標位於一個地毯的覆蓋範圍之內,就結束查找,輸出該數據的編號;否則全部查找失敗後,仍未找到的則輸出-1。
C語言地毯問題
以前學習C語言的時候,看的是如鵬網的視頻教程《C語言也能幹大事》
通過C語言開發遊戲,開發網站的方式來講解C語言,蠻有成就感的
用c語言畫矩形
每行起始和結束字符均是你的第3個參數
矩形第1行和最後一行中間是第3個參數,其他行根據第4個參數決定是空格或者第3個參數
程序可以這樣寫:
…
for ( m=0;ma;m++ )
{
printf(“%c”,c); //第1列
if ( m==0 || m==a-1 ) //第1行和最後一行
for ( n=1;nb-1;n++ ) printf(“%c”,c);
else //中間的行
for ( n=1;nb-1;n++ ) if ( d==0 ) printf(” “); else printf(“%c”,c); //空心或否
printf(“%c\n”,c); //最後1列
}
或者可以寫:
for ( m=0;ma;m++ )
{
printf(“%c”,c); //第1列
if ( m==0 || m==a-1 || d!=0) for ( n=1;nb-1;n++ ) printf(“%c”,c);
else for ( n=1;nb-1;n++ ) printf(” “);
printf(“%c\n”,c); //最後1列
}
用C語言畫矩形
/* 旋轉的立體橢球 */
#include graphics.h
#include math.h
#include conio.h
#define PI 3.14159
#define T PI/180
#define NN 36
#define DT PI/NN
#define DIST 0.8
#define R 190
static int n=1;
void trans(t,s)
float t[3];
float s[3][3];
{
s[0][0]=cos(t[1])*cos(t[2]); s[0][1]=cos(t[1])*sin(t[2]);
s[0][2]=-sin(t[1]);
s[1][0]=sin(t[0])*sin(t[1])*cos(t[2])-cos(t[0])*sin(t[2]);
s[1][1]=sin(t[0])*sin(t[1])*sin(t[2])+cos(t[0])*cos(t[2]);
s[1][2]=sin(t[0])*cos(t[1]);
s[2][0]=cos(t[0])*sin(t[1])*cos(t[2])+sin(t[0])*sin(t[2]);
s[2][1]=cos(t[0])*sin(t[0])*sin(t[2])-sin(t[0])*cos(t[2]);
s[2][2]=cos(t[0])*cos(t[1]);
}
void draw(m,da,db)
float m[3][3],da,db;
{
float f[3],f0 , x0,y0,x1,y1,x2,y2;
f[0]=R*sin(da)*cos(db); f[1]=R*sin(da)*sin(db);
f[2]=R*cos(da);
f0=f[0]*m[0][2]+f[1]*m[1][2]+f[2]*m[2][2];
if(f0=0) n=1;
else
{
x0=300.0;y0=165.0;
x2=(m[0][0]*f[0]+m[1][0]*f[1]+m[2][0]*f[2])+x0;
y2=(m[0][1]*f[0]+m[1][1]*f[1]+m[2][1]*f[2])*DIST+y0;
if(n==1) {n=2;x1=x2;y1=y2;}
else
{
line(x1,y1,x2,y2);
x1=x2;y1=y2;
}
}
}
main()
{
float d[3],r[3][3],ta,tb;
char k;
int gdriver=VGA,gmode=VGAMED, i,p=1;
initgraph(gdriver,gmode,”c:\\tc”);
setbkcolor(BLACK);setcolor(GREEN);
d[1]=30*T; d[2]=10*T;
do{
for(i=0;i=361;i+=1)
{
k=kbhit();
if(k!=0)break;
setactivepage(p);
d[0]=i*T;
cleardevice();
trans(d,r);
for(tb=0.0;tbPI;tb+=DT)
{
n=1;
for(ta=0.0;ta2.1*PI;ta+=DT) draw(r,ta,tb);}
for(ta=0.0;taPI;ta+=DT)
{
n=1;
for(tb=0.0;tb2.1*PI;tb+=DT) draw(r,ta,tb);
}
setvisualpage(p);delay(150);p=1-p;
}
}
while(k==0);
getch();closegraph();
}
這是旋轉橢球的
C語言怎麼畫矩形??
用lineto函數畫矩形
#includegraphics.h
main()
{int gdriver=DETECT,gmode;
initgraph(gdriver,gmode,”c:\\tc”);
cleardevice();
moveto(160,120);
lineto(480,120);
lineto(160,360);
lineto(160120);
getch();
closegraph();
}
圖形和圖像函數包含在graphics.h裡面
rectangle() 畫矩形函數
功能: 函數rectangle() 用當前繪圖色、線型及線寬,畫一個給定左上角與右下角的矩形(正方形或長方形)。
用法: 此函數調用方式為void rectangle(int left,int top,int right,int bottom);
說明: 參數left,top是左上角點坐標,right,bottom是右下角點坐標。如果有一個以上角點不在當前圖形視口內,且裁剪標誌clip設置的是真(1),那麼調用該函數後,只有在圖形視口內的矩形部分才被畫出。
這個函數對應的頭文件為graphics.h
返回值: 無
例: 下面的程序畫一些矩形實例:
#i ncludegraphics.h
void main()
{
int driver,mode;
driver=DETECT;
mode=0;
initgrpah(driver,mode,””);
rectangle(80,80,220,200);
rectangle(140,99,180,300);
rectangle(6,6,88,88);
rectangle(168,72,260,360);
getch();
restorecrtmode();
}
謝爾賓斯基地毯 用c語言寫出生成代碼。 要完整的,不只是函數的代碼
下面我寫的程序成功畫出了圖形效果圖:
不過要用Turbo C如果沒有Turbo C去這個鏈接看看#include #include int isFilled(int x,int y,int width,int height){if(x return 0;int x2 = x*3/width;int y2 = y*3/height;if(x2 == 1y2 == 1)return 1;x -= x2*width/3;y -= y2*height/3;return isFilled(x,y,width/3,height/3);}int main(){int gdriver = VGA, gmode = VGAHI;initgraph(gdriver, gmode, “C:\\TC30\\BGI”);int i,j;for(i = 1;i {for(j = 1;j {if(isFilled(i,j,300,300))putpixel(i,j,BLACK);elseputpixel(i,j,WHITE);}}getch();}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/236411.html