C语言程序设计复习-创新互联

1.进制转换

企业建站必须是能够以充分展现企业形象为主要目的,是企业文化与产品对外扩展宣传的重要窗口,一个合格的网站不仅仅能为公司带来巨大的互联网上的收集和信息发布平台,成都创新互联公司面向各种领域:成都社区文化墙成都网站设计成都全网营销推广解决方案、网站设计等建站排名服务。

2.数据类型字节长度(P18)

3.赋值、逻辑表达式、与或非

#includeint main() {
    int a = 1;
    bool ans = (a == 1 and a == 0);
    printf("%d", ans);
}

4.除法、取模

#includeint main() {
	//除法:负负得正 
	printf("%d\t", 11 / -5);//-2
	printf("%d\t", -11 / 5);//-2
	printf("%d\n", -11 / -5);//2

	//取模:与被除数同号 
	printf("%d\t", 11 % -5);//1
	printf("%d\t", -11 % 5);//-1
	printf("%d\n", -11 % -5);//-1 
}

5.强制转换、浮点数

#includeint main() {
	float a = 10.0;
	int b = 1;
	printf("%f\t", a + b);
	printf("%f", a + (float)b);
}

6.运算符简写

#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.转义字符

#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.条件、条件表达式

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

最小公倍数

#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.函数

【1】阶乘

#includeint main() {
	int a;
	int re = 1;
	scanf("%d", &a);
	while (a) {
		re *= a;
		a--;
	}
	printf("%d", re);
}

【2】斐波那契数列

#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.数组

【1】一维数组

#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】二维数组

#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;
}

。。。

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


文章题目:C语言程序设计复习-创新互联
本文地址:http://ybzwz.com/article/eiohc.html