使用循环
Sample In
2 4
Sample Out
2468
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	int a, n;
	int ia, i, sum;
 
	ia=i=sum=0;
 
	scanf("%d %d", &a, &n);
 
	while (i<n) {
		ia = ia*10 + a;
		sum = sum + ia;
		i++;
	}
 
	printf(&qu...			
			
			阅读全文
			
		
				计算 s= 1+2+3+ ... +n
Sample In
100
Sample Out
5050
for循环的第1种写法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
 
#define NUM 10
 
int main(int argc, char *argv[])
{
	int i, sum=0;
 
	for (i=1; i<=NUM; i++) {
		sum = sum + i;
	}
 
	printf("%dn", sum);
	return 0;
}#include <stdio.h>
...			
			
			阅读全文
			
		
				判断学生成绩是否合格
Sample In
5
12 56 60 59 98
Sample Out
Fail
Fail
Pass
Fail
Pass
使用for循环
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	int i, num, score;
 
	scanf("%d", &num);
	for (i=0; i<num; i++) {
		scanf("%d", &score);
		if&...			
			
			阅读全文
			
		
				for循环
Sample In
5
Sample Out
0 2 4 6 8
使用for循环
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	int i, n;
 
	scanf("%d", &n);
 
	for(i=0; i<n; i++) {
		printf("%4d", 2*i);
	}
 
	printf("n");
	return 0;
}#include &l...			
			
			阅读全文
			
		
				输入若干件商品的购买价格,计算总价格,当输入0时结束。
输入的价格为正整数
Sample Input
1 2 3 4 5 0
Sample Output
15
do while 循环
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
 
int main(int argc, char *argv[])
{
	int price, sum;
 
	sum = 0;
	do {
		scanf("%d", &price);
		sum = sum + price;
	} while( price!=0)...			
			
			阅读全文
			
		
				计算表达式
1
2
3
4
5
6
7
8
#include<stdio.h>
#include<math.h>
 
int main()
{
	printf("%.8lfn", 1+2*sqrt(3)/(5-0.1));
	return 0;
}#include<stdio.h>
#include<math.h>
int main()
{
	printf("%.8lfn", 1+2*sqrt(3)/(5-0.1));
	return 0;
}
读者可能还是有一些疑惑:5-0.1的值是什么?“整数-浮点数”是整数还是浮点数...			
			
			阅读全文
			
		
				这部分内容展示了C语言的精髓:简洁、精炼。本节包含了四个超级经典的程序:文件复制,字符计数,行计数,单词计数。
接下来我们看一组与字符型数据处理有关的程序。读者将会发现,许多程序只不过是这里所讨论的程序原型的扩充版本而已。
标准库提供的输入/输出模型非常简单。无论文本从何处输入,输出到何处,其输入/输出都是按照字符流的方式处理。文本流是由多行字符构成的字符序列,而每行字符则由 0个或多个字符组成,...			
			
			阅读全文
			
		
					
	
	
	
	
	
	
	
