作业:

1、1. 打印100~200 之间的素数

#include <stdio.h>

#include <math.h>

 

int main()

{

int i = 0;

int count = 0;

for(i = 101;i<=200;i+=2)

{

int j = 0;

for(j = 2;j<=sqrt(i);j++)

{

if(i%j == 0)

{

break;

}

}

if(j > sqrt(i))

{

count++;

printf("%d ",i);

}

}

printf("count = %d\n",count);

return 0;

}

2. 输出乘法口诀表

#include <stdio.h>

int main()
{
	int i = 0;
	int j = 0;
	for (i = 1; i <= 9; i++)
	{
		for (j = 1; j <= i; j++)
		{
			printf("%d*%d=%2d ", i, j, i*j);
		}
		printf("\n");
	}
	return 0;
}

3、判断1000年---2000年之间的闰年

#include <stdio.h>
 
int main()
{
int count = 0;
int year = 0;
for(year = 1000;year <=2000;year++)
{
if(year % 4 == 0)
{
if(year % 100 != 0)
{
printf("%d ",year);
count++;
}
}
if(year % 400 == 0)
{
printf("%d ",year);
count++;
}
}
printf("\ncount = %d\n",count);
return 0;
}


1、return 0可以随时终止程序,返回值为void的函数,可以用return;

2、字符串用“”

3、字符串“ ”与指针

例如:char *p=" ";

4.输出"hello world"de 四种方法

(1)printf("hello world");

(2)printf("%s","hello world");

(3)char *p="hello world";

    printf("%s",p);

(4)char *p="hello world";

    printf(p);

程序如下:

#include <stdio.h>
 
int main()
{
int i = 10;
printf("%d%d",i,j);
char *p = "hello world\n";
printf("hello world\n");
printf("%s","hello world\n");
printf("%s",p);
printf(p);
return 0;
}

5、%nd,占n个字符宽度且有对齐

6、素数求解的多种方法

7、/*...*/注释位置自动变成空格

例如:in/*...*/t  main()相当于in t main(),是错误的

8、三字母词:例如??)相当与]

9、转义字符

例:/a 蜂鸣

    /n空格

10、八进制输出和十六进制输出

待续

11、c语言中有字符串,但无字符串类型

12、strlen()是一个库函数,定义在<string.h>中,用于求字符串长度

13."asc\0",\0是字符串结束的标志,告诉计算机到哪里结束

14、枚举常量的简单应用

#include <stdio.h>
#include<stdlib.h>

enum OS_TYPE
{
	LINUX = 10,
	WIN,
	UNIX
};
int main()
{
	enum OS_TYPE os_type = LINUX;
	printf("%d\n", os_type);
	os_type = WIN;
	printf("%d\n", os_type);
	os_type = UNIX;
	printf("%d\n", os_type);
	system("pause");
	return 0;
}

15、牛客网