C Program to Find Prime Number between 1 to 100

Prime Number between 1 to 100 in C

 

Here, in this page we will discuss the program to find prime number between 1 to 100 in C .We know that,the whole number are the basic counting number 0,1,2,3….and so on.So A whole number greater than 1 that can not be made by multiplying other whole numbers.

Example-7 is a prime number because 7 is only divisible by one or itself.It can not be divisible by 2,3,4,5,6.

So prime number has two factor is 1 and number itself is called prime number. The number 1 is neither prime nor composite.

Prime number

Implementation of Prime number between 1 to 100

  • First of all we will initialize i,j and count=0 variable.
  • the loop is start i=2 to less then equal 100 and second loop start j=1 to less then or equal i.
  • the condition is i%j=0.
  • and the value of count is increment after the iteration of the loop.
  • and then count value equal of two then print the i. because prime number has only two factor one is 1 and another by the number
Prime number between 1 to 100 in C

Code in C

//C Code to print prime number 1 to 100
#include<stdio.h>  
//Main function
int main()
{
  int i,j,count=0;
  //print values between 1 to 100
  printf("The value between 1 to 100\n");
  for(i=2;i<=100;i++)
  {
     for(j=1;j<=i;j++)
     {
       if(i%j==0)
         count++;
     }
     if(count==2)
      printf("%d",i);
     count=0;
  }
}
Output:
The value between 1 to 100
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