Saturday, 5 January 2019

Filled Under:

Prime number below a range[c programming examples with output]

C programming examples with output

Prime number below a range
Program

#include<stdio.h>
#include<conio.h>
main()
{
      int a,b,c=0,r;
      clrscr();
      printf("Enter range  :");
      scanf("%d",&r);
      a=1;
      while(a<=r)
      {
         b=1;c=0;
      while(b<=a)
      {
         if(a%b==0)
         c=c+1;
         b++;
      }
         if(c==2)
         printf("\n%d is a prime number",a);
         a++;
      }
      getch():
}

Output
Enter range:20
2 is a prime number
3 is a prime number
5 is a prime number
7 is a prime number
11 is a prime number
13 is a prime number
17 is a prime number
19  is a prime number

0 komentar:

Post a Comment