C program to print prime numbers upto n terms
Answers
Answered by
2
Here you go
#include <stdio.h>
int main()
{
int limit, num, count, temp;
printf("Enter the Limit:\t");
scanf("%d", &limit);
for(num = 2; num <= limit; num++)
{
for(count = 2; count < num; count++)
{
if(num % count == 0)
{
temp = 0;
break;
}
temp = 1;
}
if(temp == 1)
{
printf("\n%d is a Prime Number", num);
}
else if(temp == 0)
{
printf("\n%d is Not a Prime Number", num);
}
}
printf("\n");
return 0;
}
#include <stdio.h>
int main()
{
int limit, num, count, temp;
printf("Enter the Limit:\t");
scanf("%d", &limit);
for(num = 2; num <= limit; num++)
{
for(count = 2; count < num; count++)
{
if(num % count == 0)
{
temp = 0;
break;
}
temp = 1;
}
if(temp == 1)
{
printf("\n%d is a Prime Number", num);
}
else if(temp == 0)
{
printf("\n%d is Not a Prime Number", num);
}
}
printf("\n");
return 0;
}
Answered by
1
/* C program to print prime numbers */#include<stdio.h> void main(){ int n,i,j,ct=0; printf("Enter any number \n"); scanf("%d",&n); printf(" All prime numbers are -\n"); for(i=2;i<=n;i++) { ct=0; for(j=2;j<i;j++) { if(i%j==0) { ct=1; break; } } if(ct==0) { printf("%d \t",i); } } getch();}
Similar questions