Prime Number :
A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. (or)
A number that is divisible only by itself and 1, prime numbers are very useful in cryptography.
Ex : 2, 3, 5, 7, 11, 13, 17, 19, 23..etc
File Name : prime.c
#include<stdio.h>
void main()
{
int n,c=0,i,j;
printf("Enter a number to generate Prime Numbers Series:");
scanf("%d",&n);
printf("Generated Prime Numbers Between 1 and %d are:\n",n);
for(i=1; i<=n; i++)
{
c=0;
for(j=1;j<=n;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d\n",i);
}
}
Output:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, etc.
A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. (or)
A number that is divisible only by itself and 1, prime numbers are very useful in cryptography.
Ex : 2, 3, 5, 7, 11, 13, 17, 19, 23..etc
File Name : prime.c
#include<stdio.h>
void main()
{
int n,c=0,i,j;
printf("Enter a number to generate Prime Numbers Series:");
scanf("%d",&n);
printf("Generated Prime Numbers Between 1 and %d are:\n",n);
for(i=1; i<=n; i++)
{
c=0;
for(j=1;j<=n;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d\n",i);
}
}
Output:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, etc.
No comments:
Post a Comment