入门级代码编写

-100-200之间的素数

#include <stdio.h>
int main(){
	int i = 100;
	int count = 0;
	while (i <= 200){
		int j = 2;
		while (j <= i){
			if (i % j == 0){
				break;
			}
			j++;
		}
		if (j == i){
			count++;
			printf("%d ", i);
		}
		i++;
	}
		printf("\ncount = %d\n", count);
		system("pause");
		return 0;
	}

-乘法口诀表

#include<stdio.h>
int main(){
   int i = 1;
   while (i <= 9){
   	int j = 1;
   	while (j <= i){
   		printf("%d * %d = %d ", i, j, i * j);
   		j++;
   	}
   	printf("\n");
   	i++;
   }
   system("pause");
   return 0;
}

-1000-2000年的闰年

#include<stdio.h>
int main(){
   int i = 1000;
   int count = 0;
   while (i <= 2000){
   	if (i % 4 == 0){
   		if (i % 100!= 0){
   			printf("%d ", i);
   		}
   		count++;
   	}
   	if (i % 400 == 0){
   		printf("%d ", i);
   	}
   	i++;
   }
   system("pause");
   return 0;
}

这些都是用while 循环写的,在接下来的学习会不断优化改进代码,期待优化版的!

更多推荐

入门级代码编写