国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C語言程序開發經典實例之六

2019-11-17 05:11:22
字體:
來源:轉載
供稿:網友
【程序51】

  題目:學習使用按位與 & 。   

  1.程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1



  2.程序源代碼:

#include "stdio.h"
main()
{
 int a,b;
 a=077;
 b=a&3;
  b&=7;
 printf("/40: The a & b(decimal) is %d /n",b);
}
  【程序52】

  題目:學習使用按位或 。

  1.程序分析:00=0; 01=1; 10=1; 11=1            

  2.程序源代碼:

#include "stdio.h"
main()
{
 int a,b;
 a=077;
 b=a3;
 printf("/40: The a & b(decimal) is %d /n",b);
 b=7;
 printf("/40: The a & b(decimal) is %d /n",b);
}
  【程序53】

  題目:學習使用按位異或 ^ 。   

  1.程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0

  2.程序源代碼:

#include "stdio.h"
main()
{
 int a,b;
 a=077;
 b=a^3;
 printf("/40: The a & b(decimal) is %d /n",b);
 b^=7;
 printf("/40: The a & b(decimal) is %d /n",b);
} 更多文章 更多內容請看C/C++進階技術文檔  Wlan組網----家庭專題專題,或
【程序54】

  題目:取一個整數a從右端開始的4~7位。

  程序分析:可以這樣考慮:

  (1)先使a右移4位。

  (2)設置一個低4位全為1,其余全為0的數。可用~(~0<<4)

  (3)將上面二者進行&運算。

  2.程序源代碼:

main()
{
 unsigned a,b,c,d;
 scanf("%o",&a);
 b=a>>4;
 c=~(~0<<4);
 d=b&c;
 printf("%o/n%o/n",a,d);
}
  【程序55】

  題目:學習使用按位取反~。   

  1.程序分析:~0=1; ~1=0;

  2.程序源代碼:

#include "stdio.h"
main()
{
 int a,b;
 a=234;
 b=~a;
 printf("/40: The a's 1 complement(decimal) is %d /n",b);
 a=~a;
 printf("/40: The a's 1 complement(hexidecimal) is %x /n",a);
}
  【程序56】

  題目:畫圖,學用circle畫圓形。   

  1.程序分析:

  2.程序源代碼:

/*circle*/
#include "graphics.h"
main()
{
 int driver,mode,i;
 float j=1,k=1;
 driver=VGA;mode=VGAHI;
 initgraph(&driver,&mode,"");
 setbkcolor(YELLOW);
 for(i=0;i<=25;i++)
 {
  setcolor(8);
  circle(310,250,k);
  k=k+j;
  j=j+0.3;
 }
}
  【程序57】

  題目:畫圖,學用line畫直線。

  1.程序分析:           

  2.程序源代碼:

#include "graphics.h"
main()
{
 int driver,mode,i;
 float x0,y0,y1,x1;
 float j=12,k;
 driver=VGA;mode=VGAHI;
 initgraph(&driver,&mode,"");
 setbkcolor(GREEN);
 x0=263;y0=263;y1=275;x1=275;
 for(i=0;i<=18;i++)
 {
  setcolor(5);
  line(x0,y0,x0,y1);
  x0=x0-5;
  y0=y0-5;
  x1=x1+5;
  y1=y1+5;
  j=j+10;
 }
 x0=263;y1=275;y0=263;
 for(i=0;i<=20;i++)
 {
  setcolor(5);
  line(x0,y0,x0,y1);
  x0=x0+5;
  y0=y0+5;
  y1=y1-5;
 }
} 更多文章 更多內容請看C/C++進階技術文檔  Wlan組網----家庭專題專題,或

【程序58】

  題目:畫圖,學用rectangle畫方形。   

  1.程序分析:利用for循環控制100-999個數,每個數分解出個位,十位,百位。

  2.程序源代碼:

#include "graphics.h"
main()
{
 int x0,y0,y1,x1,driver,mode,i;
 driver=VGA;mode=VGAHI;
 initgraph(&driver,&mode,"");
 setbkcolor(YELLOW);
 x0=263;y0=263;y1=275;x1=275;
 for(i=0;i<=18;i++)
 {
  setcolor(1);
  rectangle(x0,y0,x1,y1);
  x0=x0-5;
  y0=y0-5;
  x1=x1+5;
  y1=y1+5;
 }
 settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
 outtextxy(150,40,"How beautiful it is!");
 line(130,60,480,60);
 setcolor(2);
 circle(269,269,137);
}
  【程序59】

  題目:畫圖,綜合例子。

  1.程序分析:

  2.程序源代碼:

# define PAI 3.1415926
# define B 0.809
# include "graphics.h"
#include "math.h"
main()
{
int i,j,k,x0,y0,x,y,driver,mode;
float a;
driver=CGA;mode=CGAC0;
initgraph(&driver,&mode,"");
setcolor(3);
setbkcolor(GREEN);
x0=150;y0=100;
circle(x0,y0,10);
circle(x0,y0,20);
circle(x0,y0,50);
for(i=0;i<16;i++)
{
 a=(2*PAI/16)*i;
 x=ceil(x0+48*cos(a));
 y=ceil(y0+48*sin(a)*B);
 setcolor(2); line(x0,y0,x,y);}
setcolor(3);circle(x0,y0,60);
/* Make 0 time normal size letters */
settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
outtextxy(10,170,"press a key");
getch();
setfillstyle(HATCH_FILL,YELLOW);
floodfill(202,100,WHITE);
getch();
for(k=0;k<=500;k++)
{
 setcolor(3);
 for(i=0;i<=16;i++)
 {
  a=(2*PAI/16)*i+(2*PAI/180)*k;
  x=ceil(x0+48*cos(a));
  y=ceil(y0+48+sin(a)*B);
  setcolor(2); line(x0,y0,x,y);
 }
 for(j=1;j<=50;j++)
 {
  a=(2*PAI/16)*i+(2*PAI/180)*k-1;
  x=ceil(x0+48*cos(a));
  y=ceil(y0+48*sin(a)*B);
  line(x0,y0,x,y);
 }
}
restorecrtmode();
}
  【程序60】

  題目:畫圖,綜合例子。   

  1.程序分析:

  2.程序源代碼:

#include "graphics.h"
#define LEFT 0
#define TOP 0
#define RIGHT 639
#define BOTTOM 479
#define LINES 400
#define MAXCOLOR 15
main()
{
int driver,mode,error;
int x1,y1;
int x2,y2;
int dx1,dy1,dx2,dy2,i=1;
int count=0;
int color=0;
driver=VGA;
mode=VGAHI;
initgraph(&driver,&mode,"");
x1=x2=y1=y2=10;
dx1=dy1=2;
dx2=dy2=3;
while(!kbhit())
{
 line(x1,y1,x2,y2);
 x1+=dx1;y1+=dy1;
 x2+=dx2;y2+dy2;
 if(x1<=LEFTx1>=RIGHT)
 dx1=-dx1;
 if(y1<=TOPy1>=BOTTOM)
  dy1=-dy1;
 if(x2<=LEFTx2>=RIGHT)
  dx2=-dx2;
 if(y2<=TOPy2>=BOTTOM)
  dy2=-dy2;
 if(++count>LINES)
 {
  setcolor(color);
  color=(color>=MAXCOLOR)?0:++color;
 }
}
closegraph();
} 更多文章 更多內容請看C/C++進階技術文檔 
 Wlan組網----家庭專題專題,或

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄂州市| 桐柏县| 克什克腾旗| 绥化市| 吉木乃县| 孙吴县| 绿春县| 泰兴市| 远安县| 大连市| 冀州市| 昌平区| 山阳县| 田林县| 涟水县| 巴彦淖尔市| 和林格尔县| 西乌珠穆沁旗| 通州市| 东阳市| 嘉峪关市| 平利县| 西盟| 繁峙县| 乾安县| 毕节市| 神木县| 弥勒县| 陕西省| 图木舒克市| 泽普县| 秀山| 永和县| 凤庆县| 定陶县| 桂东县| 重庆市| 革吉县| 公主岭市| 来凤县| 梁平县|