write a program to print prime numbers upto a certain number....
Answers
Answered by
1
We already have a C Program to Print prime numbers in a given range based on Max and Min
PROGRAM:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
void main()
{
int n,i,fact,j;
printf("Enter the Number");
scanf("%d",&n);
printf("Prime Numbers are: \n");
for(i=1; i<=n; i++)
{
fact=0;
for(j=1; j<=n; j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf("%d " ,i);
}
getch();
}
OUTPUT:
Enter the Number50 Prime Numbers are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
PROGRAM:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
void main()
{
int n,i,fact,j;
printf("Enter the Number");
scanf("%d",&n);
printf("Prime Numbers are: \n");
for(i=1; i<=n; i++)
{
fact=0;
for(j=1; j<=n; j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf("%d " ,i);
}
getch();
}
OUTPUT:
Enter the Number50 Prime Numbers are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
atharvah3p1tdc4:
hope it helps
Similar questions