adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Write a program in C to find greatest prime number less than a given positive number.

Write a program in C to find greatest prime number less than a given positive number.




#include<stdio.h>
#include<conio.h>
  void main()
   {
   int i,n,n1,p,m=0;
   clrscr();
   printf("Enter a no:-");
   scanf("%d",&n1);
   for(n=1;n<=n1;n++)
     {
     for(p=1,i=2;i<n;i++)
      {
       if(n%i==0)
        {
          p=0;
          break;
        }
       }
     if(p==1)
       m=0;
       if(p>m)
         m=n;
       }
     printf("\n%d is greatest prime no..",m);
     getch();
    }
Output:-

Post a Comment

0 Comments