C语言练手小代码---one

1. 打印100~200 之间的素数
#define _CRT_SECURE_NO_WARNINGS ch
#include<stdio.h>
#include<Windows.h>

int main(){
	int i = 0;
	int j = 0;
	int count = 0;
	for (i = 101; i <200; i+=2){//去除偶数
		for (j = 2; j < i; j++){
			if (0 == i%j){
				break;
			}
		}
		if (i == j){
			printf("%d ", i);
			count++;
		}
	}
	printf("count=%d", count);
	system("pause");
	return 0;

运行结果:

2. 输出乘法口诀表
#define _CRT_SECURE_NO_WARNINGS ch
#include<stdio.h>
#include<Windows.h>

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

运行结果:
3. 判断1000年---2000年之间的闰年
 
 
#define _CRT_SECURE_NO_WARNINGS ch
#include<stdio.h>
#include<Windows.h>

int main(){
	int i = 0;
	int count = 0;
	for (i = 1000; i <=2000; i++){
		if (((0 == i % 4) && (i % 100 != 0)) || (0 == i % 400)){
			printf("%d ", i);
			count++;
		}
	}
	printf("count=%d", count);
	system("pause");
	return 0;
}
运行结果:

猜你喜欢

转载自blog.csdn.net/superwangxinrui/article/details/79949659