Thursday, February 7, 2019

Generating Prime numbers using "C-Language" in Ubuntu.

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.

No comments:

Post a Comment

Hadoop Commands

HADOOP COMMANDS OS : Ubuntu Environment Author : Bottu Gurunadha Rao Created: 31-Jan-2022 Updated: 31-Jan-2022 Release  : 1.0.1 Purpose: To ...

Search This Blog