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

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

C程序開發經典實例之6

2019-11-17 05:40:52
字體:
來源:轉載
供稿:網友

【程序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"
/* 歡迎訪問 C++Builder研究 - www.ccrun.com */
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);
}

【程序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);
}

【程序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"
/* 63 63 72 75 6E 2E 63 6F 6D */
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;
    }
}

【程序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"
/* 歡迎訪問 C++Builder研究 - www.ccrun.com */
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(x

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新河县| 顺平县| 隆回县| 利辛县| 渭源县| 南乐县| 广宁县| 凉山| 进贤县| 家居| 谷城县| 社旗县| 黔西| 庄浪县| 泽州县| 武穴市| 溧水县| 出国| 宁远县| 恩施市| 板桥市| 凤山市| 余干县| 长春市| 临江市| 名山县| 宁蒗| 尚义县| 永济市| 体育| 峨眉山市| 牟定县| 洪江市| 政和县| 百色市| 富裕县| 潼南县| 林西县| 建瓯市| 九寨沟县| 若羌县|