WAP to print the list of prime numbers up to given number

Write a program to print the list of prime numbers up to given number

#include<stdio.h>

int main() {
	int j,i,n,count;
	printf("Enter the upper limit: ");
	scanf("%d",&n);
	for(j=1;j<=n;j++) {
		count=0;
		for(i=1;i<=j;i++) {
			if(j%i==0)
			count++;
			if(count>2)
			break;
		}
		if(count==2)
		printf("%d\n",j);
	}
}

Output

WAP to print the list of prime numbers up to given number
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments