c程式語言筆記1

2021-06-04 20:05:13 字數 2935 閱讀 7810

列印最長輸入行的程式:

#include #define maxline 1000	/*允許的輸入行的最大長度*/

int getline(char line, int maxline);

void copy(char to, char from);

/* 列印最長的輸入行 */

main()

if (max > 0)

printf("%s",longest);

return 0;

}/* getline函式:將一行讀入到s並返回其長度 */

int getline(char s, int lim)

s[i] = '\0';

return i;

}/* copy函式:將from複製到to;這裡假定to足夠大 */

void copy(char to, char from)

練習1-9 編寫乙個將輸入複製到輸出的程式,並將其中連續的多個空格用乙個空格代替。

#include /* ex1-9,編寫乙個將輸入複製到輸出的程式,並將其中的連續多個空格用乙個空格代替*/

#define nonblack 'a'

/*main()

else if(c_prior != ' '&& i > 0)

putchar(c);

c_prior = c;

} getch();

} */

//or版本

main()

getch();

}

練習1-12 

#include // ex 1-12  以每行乙個單詞的形式列印其輸入

#define in 1 // inside a word

#define out 0 // outside a word

main()

else if(state == out)

else

putchar(c);

} }}

練習1-13 

水平直方圖:

#include #include //ex 1-13

//print horizontal histogram

#define maxhist 15 /* max length of histogram */

#define maxword 11 /* max length of a word */

#define in 1 /* inside a word */

#define out 0 /* outside a word */

main()

else if (state == out)else

nc++; /*inside a word */

} maxvalue = 0;

for (i = 1;i < maxword; i++)

if (wl[i] > maxvalue)

maxvalue = wl[i];

for (i = 1;i < maxword; i++)else

len = 0; */

len = wl [i];

while (len > 0)

putchar('\n');

} if (ovflow > 0)

printf("there are %d words >= %d\n", ovflow , maxword);

system("pause");

}

垂直直方圖:

#include #include //ex 1-13

//print horizontal histogram

#define maxhist 15 /* max length of histogram */

#define maxword 11 /* max length of a word */

#define in 1 /* inside a word */

#define out 0 /* outside a word */

main()

else if (state == out)else

nc++; /*inside a word */

} maxvalue = 0;

for (i = 1;i < maxword; i++)

if (wl[i] > maxvalue)

maxvalue = wl[i];

for (i = maxhist;i > 0; --i)

for (i = 1;i < maxword; ++i)

printf("%4d ",i);

putchar('\n');

for (i = 1; i < maxword; ++i)

printf("%4d ",wl[i]);

putchar('\n');

if (ovflow > 0)

printf("there are %d words >= %d\n", ovflow , maxword);

system("pause");

}

練習1-20detab函式

#include #include // ex 1-20 編寫程式detab

#define tabinc 8 /* tab increment size */

/* replace tabs with the proper number of blanks */

main()

}else if (c == '\n')else

} system("pause");

}

C語言程式設計課程筆記1

2018級 數學 四班 2018212773 張越 first 知識點總結 一 c資料型別 1.c語言程式處理的資料型別分類 4類 基本型別有 整型 int 4個位元組 long 4 short 2 unsigned.實型 float 4 double 8 long double 10 字元型 ch...

C程式語言(K R) 筆記1

當作複習。1 將華氏度 換算成 攝氏度,公式 5 9 f 32 include int transformtemprature int f int main return0 lenovo myc lenovomyc lenovo product c test vim temprature.c len...

c語言與程式設計筆記 指標篇 (1)

基本概念 1 運算元 稱為間接訪問表示式,它的操作語義是引用以運算元為位址的變數。運算元可以是表示式,但其值必須是位址值。所以間訪表示式的值是乙個左值,代表指標所指的變數。而指標所指的型別就是間訪表示式運算的型別。例 int y,x 3 pi x y pi 是先對pi進行 操作,然後計算px,即對p...