My Carelessness

Back to your page!


Or leave your comments here.

RegendLa

导航

关于质数

Q:输入一个整数n,输出不大于n的所有质数。

S:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	int n,t;
	int j,i;
	scanf("%d",&n);
	for(i=2;i<=n;i++)
	{
		t=sqrt(i);
		for(j=2;j<=t;j++)
		{
			if(i%j==0) break;
		}	
		if(j>t) printf("%d\n",i);	
	}
	return 0;
}

 

posted on 2014-12-02 17:12  最爱七  阅读(169)  评论(0编辑  收藏  举报




Thanks for your coming!
If what you read helps,I would appreciate!