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

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

C程序開發經典實例之4

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

標題:C 程序開發經典實例之四作者: 出處: 更新時間: 2006年03月09日
題目:請輸入星期幾的第一個字母來判定一下是星期幾,假如第一個字母一樣,則繼續判定第二個字母。
1.程序分析:用情況語句比較好,假如第一個字母一樣,則判定用情況語句或if語句判定第二個字母。
2.程序源代碼:
void main()
{
    char letter;
        while((letter = getch()) != 'Y') /* 當所按字母為Y時才結束 */
    {
        switch (letter)
        {
        case 'S':
            printf("please input second letter/n");
            if((letter = getch()) == 'a')
                printf("saturday/n");
            else if ((letter = getch()) == 'u')
                printf("sunday/n");
            else printf("data error/n");
                break;
        case 'F': printf("friday/n");break;
        case 'M': printf("monday/n");break;
        case 'T':
            printf("please input second letter/n");
            if((letter = getch()) == 'u')
                printf("tuesday/n");
            else if ((letter = getch()) == 'h')
                printf("thursday/n");
            else printf("data error/n");
                break;
        case 'W': printf("wednesday/n"); break;
        default: printf("data error/n");
        }
    }
}

【程序32】
題目:Press any key to change color, do you want to try it. Please hurry up!
1.程序分析: 
2.程序源代碼:
#include <conio.h>
/* 歡迎訪問 C++Builder研究 - www.ccrun.com */
void main(void)

{
    int color;
    for (color = 0; color < 8; color++)
    {
        textbackground(color);/*設置文本的背景顏色*/
        cprintf("This is color %d/r/n", color);
        cprintf("Press any key to continue/r/n");
        getch(); /* 輸入字符看不見 */
    }
}

【程序33】
題目:學習gotoxy()與clrscr()函數 
1.程序分析: 
2.程序源代碼:
#include <conio.h>
void main(void)
{
    clrscr(); /* 清屏函數 */
    textbackground(2);
    gotoxy(1, 5); /* 定位函數 */
    cprintf("Output at row 5 column 1/n");
    textbackground(3);
    gotoxy(20, 10);
    cprintf("Output at row 10 column 20/n");
}

【程序34】
題目:練習函數調用
1. 程序分析:
2.程序源代碼:
#include <conio.h>
void hello_world(void)
{
    printf("Hello, world!/n");
}
void three_hellos(void)
{
    int counter;
    for(counter=1; counter<=3; counter++)
        hello_world(); /* 調用此函數 */
}
void main(void)
{
    three_hellos(); /* 調用此函數 */
}

【程序35】
題目:文本顏色設置
1.程序分析:
2.程序源代碼:
#include <conio.h>
void main(void)
/* 63 63 72 75 6E 2E 63 6F 6D */
{
    int color;
    for(color=1; color<16; color++)
    {
        textcolor(color); /* 設置文本顏色 */
        cprintf("This is color %d/r/n", color);
    }
    textcolor(128 + 15);
    cprintf("This is blinking/r/n");
}

【程序36】
題目:求100之內的素數 
1.程序分析:
2.程序源代碼:
#include <conio.h>
#include "math.h"
#define N 101
main()
{
    int i, j, line, a[N];
    for(i=2; i<100; i++)
        for(j=i+1; j<100; j++)
        {
            if(a[i] != 0 && a[j] != 0)

                if(a[j] % a[i] == 0)
                    a[j] = 0;
        }
    printf("/n");
    for(i=2, line=0; i<100; i++)
    {
        if(a[i] != 0)
        {
            printf("%5d", a[i]);
            line++;
        }
        if(line==10)
        {
            printf("/n");
            line = 0;
        }
    }
}

【程序37】
題目:對10個數進行排序
1.程序分析:可以利用選擇法,即從后9個比較過程中,選擇一個最小的與第一個元素交換,下次類推,即用第二個元素與后8個進行比較,并進行交換。
2.程序源代碼: 
#define N 10
main()
{
    int i, j, min, tem, a[N];
    /* input data */
    printf("please input ten num:/n");
    for(i=0; i<10; i++)
    {
        printf("a[%d]=", i);
        scanf("%d", &a[i]);
    }
    printf("/n");
    for(i=0; i<10; i++)
        printf("%5d", a[i]);
    printf("/n");
    /* sort ten num */
    for(i=0; i<10; i++)
    {
        min = i;
        for(j=i+1; j<10; j++)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扎兰屯市| 合江县| 磐安县| 道孚县| 房山区| 新余市| 桐柏县| 惠州市| 德州市| 炉霍县| 子长县| 建德市| 乌兰县| 石楼县| 甘孜| 灌阳县| 吉首市| 曲周县| 马龙县| 益阳市| 双辽市| 金塔县| 黑水县| 金乡县| 城固县| 自贡市| 岚皋县| 黄石市| 深泽县| 丹江口市| 山阳县| 桂林市| 大悟县| 舞阳县| 岳池县| 新和县| 宿州市| 荃湾区| 永嘉县| 广宁县| 资源县|