Header Ads

Prime number between 1 to 100

Program for printing prime numbers between 1 to 100

Prime numbers:
  1. Prime numbers are divisible by 1 and itself.
  2. 1 is not a prime number.
  3. All even numbers are not prime number except 2.
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,flag=1;
    printf("\"Prime numbers are those number that are divisible by itself and 1\"\n");
    printf("\'1 is not a prime number\'\n\'All even numbers are not prime number except 2\'\n\n");
    printf("Prime numbers between 1 to 100 are : \n2\t3 ");
    for(i=4;i<=100;i=i+1)
    {
        for(j=2;j<=(i-2);j++)
        {
            if(i%j==0)
            {
                flag = 0;
                 break;
            }
            flag=1;
        }
        if(flag==1)
            printf("\t%d",i);

    }
    getch();
}

Output

Screenshot of  prime number between 1 to 100
Related program:

  1. Prime number checking.


No comments