Thursday, May 30, 2019

program to print prime numbers below 100...in c


/* ***********************************************
    Write a program to print prime numbers below 100

 date:30-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

void prime_fn(int num);

void main()
{
   int n;

  // printf("Enter a number to check if it is prime\n");
  // scanf("%d",&n);
  for(n=2;n<100;n++)
  {
       prime_fn(n);
  }

   return 0;
}

void prime_fn(int num)
{
    int c;
     for ( c = 2 ; c <= num - 1 ; c++ )
   {
      if ( num%c == 0 )
      {
         //printf("%d isn't prime.\n", num);
     break;
      }
   }
   if ( c == num )
      printf("%d is prime.\n", num);
}

No comments:

Post a Comment

python class topic video