1.進(jìn)制轉(zhuǎn)換
企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對(duì)外擴(kuò)展宣傳的重要窗口,一個(gè)合格的網(wǎng)站不僅僅能為公司帶來(lái)巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺(tái),成都創(chuàng)新互聯(lián)公司面向各種領(lǐng)域:成都社區(qū)文化墻等成都網(wǎng)站設(shè)計(jì)、成都全網(wǎng)營(yíng)銷推廣解決方案、網(wǎng)站設(shè)計(jì)等建站排名服務(wù)。2.數(shù)據(jù)類型字節(jié)長(zhǎng)度(P18)
3.賦值、邏輯表達(dá)式、與或非
#includeint main() {
int a = 1;
bool ans = (a == 1 and a == 0);
printf("%d", ans);
}
4.除法、取模
#includeint main() {
//除法:負(fù)負(fù)得正
printf("%d\t", 11 / -5);//-2
printf("%d\t", -11 / 5);//-2
printf("%d\n", -11 / -5);//2
//取模:與被除數(shù)同號(hào)
printf("%d\t", 11 % -5);//1
printf("%d\t", -11 % 5);//-1
printf("%d\n", -11 % -5);//-1
}
5.強(qiáng)制轉(zhuǎn)換、浮點(diǎn)數(shù)
#includeint main() {
float a = 10.0;
int b = 1;
printf("%f\t", a + b);
printf("%f", a + (float)b);
}
6.運(yùn)算符簡(jiǎn)寫(xiě)
#includeint main() {
for (int i = 0; i< 5; i++) {
printf("%d\t", i);
}
printf("\n");
for (int i = 0; i< 5; ++i) {
printf("%d\t", i);
}
printf("\n");
int a = 0;
while (a< 5) {
a++;
printf("%d\t", a);
}
printf("\n");
int b = 0;
while (b< 5) {
b++;
printf("%d\t", b);
}
printf("\n");
int j = 0;
while (j++< 5) {
printf("%d\t", j);
}
printf("\n");
int k = 0;
while (++k< 5) {
printf("%d\t", k);
}
}
7.宏、常量
#include#define PI 3.14
const float e = 2.71;
int main() {
printf("%f\n", PI * 3);
printf("%f", e);
}
8.轉(zhuǎn)義字符
#includeint main() {
printf("'");
printf("\n");
printf("\'");
printf("\n");
printf("I say 'hi!'");
printf("\n");
printf("I say \'hi!\'");
}
9.ASCII碼
#includeint main() {
char c = 'a';
printf("%d\n", (int)c);
char e = 'A';
printf("%d\n", (int)e);
char x = '0';
printf("%d\n", (int)x);
printf("%d\n", 'a' - NULL);
}
10.輸入輸出
float a = 3.1;
printf("%7.2f", a);
11.條件、條件表達(dá)式
int a = 5;
int b = 3;
int x = ( a >b ) ? a : b;
12.switch
#includeint main() {
int a;
scanf("%d", &a);
switch (a) {
case 1:
printf("Mon");
break;
case 2:
printf("Tue");
break;
default:
break;
}
#includeint main()
{
int a = 3;
int b = 5;
char op;
scanf("%c", &op);
switch (op) {
case '*':
case 'x':
case 'X':
printf("%d", a * b);
break;
default:
break;
}
}
13.continue、break
最小公倍數(shù)
#includeint main() {
int a = 1;
while (a % 5 != 0 || a % 3 != 0) {
a++;
}
printf("%d\n", a);
int a=1;
while (a) {
if (a % 5 != 0 || a % 3 != 0) {
a++;
continue;
}
else break;
printf("hw");
}
printf("%d", a);
14.函數(shù)
【1】階乘
#includeint main() {
int a;
int re = 1;
scanf("%d", &a);
while (a) {
re *= a;
a--;
}
printf("%d", re);
}
【2】斐波那契數(shù)列
#include#include//0 1 2 3 4 5 6
//0 1 1 2 3 5 8
int fib(int x);
int fib2(int x);
int main() {
int begintime, endtime;
int a;
scanf("%d", &a);
begintime = clock();
printf("%d\n", fib2(a));
endtime = clock();
printf("Time:%dms\n", endtime - begintime);
}
int fib(int x) {
if (x == 0)return 0;
else if (x == 1) return 1;
else if (x >1) return fib(x - 1) + fib(x - 2);
else return -1;
}
int fib2(int x) {
if (x< 0) return -1;
if (x == 0)return 0;
if (x == 1)return 1;
int i = 0;
int j = 1;
for (int k = 2; k<= x; k++) {
j = i + j;
i = j - i;
}
return j;
}
【3】swap
#includeint swap1(int x, int y);
int swap2(int& x, int& y);
int swap3(int* x, int* y);
int main() {
int a = 3, b = 5;
printf("%d %d\n", a, b);
swap1(a, b);
printf("%d %d\n", a, b);
swap2(a, b);
printf("%d %d\n", a, b);
swap3(&a, &b);
printf("%d %d\n", a, b);
}
int swap1(int x, int y) {
int tmp;
tmp = x;
x = y;
y = tmp;
}
int swap2(int& x, int& y) {
int tmp;
tmp = x;
x = y;
y = tmp;
}
int swap3(int* x, int* y) {
int tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
15.數(shù)組
【1】一維數(shù)組
#includeint main() {
int a[] = { 1,2,3,4,5,6 };
int arr[10] = { 0 };
int sz = sizeof(arr) / sizeof(arr[0]);
for (int i = 0; i< sz; i++) {
printf("%d\t", arr[i]);
}
}
【2】二維數(shù)組
#includeint main()
{
int arr[3][4] = { 0 };
int i = 0;
for (i = 0; i< 3; i++)
{
int j = 0;
for (j = 0; j< 4; j++)
{
arr[i][j] = i * 4 + j;
}
}
for (i = 0; i< 3; i++)
{
int j = 0;
for (j = 0; j< 4; j++)
{
printf("%d\t", arr[i][j]);
}
printf("\n");
}
return 0;
}
。。。
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧