answersLogoWhite

0

#include <stdio.h> void main() { int n,i=1,j,c; clrscr(); printf("Enter Number Of Terms"); scanf("%d",&n);

printf("Prime Numbers Are Following");

for(i=1;i<=n;i++)

{ c=0; for(j=1;j<=i;j++) { if(i%j==0) c++; } if(c==2) printf("%d",i); } getch(); }

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
BeauBeau
You're doing better than you think!
Chat with Beau
More answers

#include <stdio.h>

int main(int, char*) {

int i, j, breakflag;

for (i = 2; i <= 100; ++i) {

breakflag = 0;

for (j = 2; j < i; ++j) {

if (i % j == 0) {

breakflag = 1;

break;

}

}

if (!breakflag) printf ("%d ", i);

}

printf ("\n");

return 0;

}

User Avatar

Wiki User

13y ago
User Avatar

It is type-dependent:

for 'int': printf ("%d", prime);

for 'long': printf ("%ld", prime);

for 'long long': printf ("%lld", prime);

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How to print prime numbers in C language program?
Write your answer...
Submit
Still have questions?
magnify glass
imp