You are here:   HomeC Programming (Pratical)C Program Print First N Prime Number using Recursion
by Dinesh Thakur Category: C Programming (Pratical)

 In this program required variable are declared for functioning criteria. Then using loop statement for fulfilling the requirement of repeat the process. Then to use if condition to check whether the number is prime or not. After finding the prime number the next process is to elaborate them using while statement or if condition if number division able by declare value then break the statement else it will increase the value for variable and then if (y==x) then return the value as required.

Problem statement:-
This program is an implementation about to print first N prime number using recursion function.

  1. Declaring Variable as required.
  2. Using required function or statements.
  3. Display result on the screen.

This C program is successfully compiled and run on a System. Output is shown below.




void main()

{
         int a[100],i,j,k,n,b;
         int prime(int);
         clrscr();
         printf("Enter no of elements : ");
         scanf("%d",&n);
         printf("Enter a no : ");
         for(i=0;i<n;i++)
             {                
                 scanf("%d",&a[i]);
             }
                for(i=0;i<n;i++)
                    {
                        b=prime(a[i]);
                        if(b==a[i])
                         {
                              printf("Prime Number is : %d\n",a[i]);
                         }
                   }
                             getch();
}
            int prime(int x)
       {
             int y=2;
             while(y<100)
                   {
                       if(x%y==0)
                         {
                             break;
                         }
                      else
                        {
                             y=y++;
                        }
                  }
                      if(y==x)
                       {
                              return x;
                       }
      }

First N Prime Number using Recursion



Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Search Content







Advance Courses



Basic Courses



Advertise with Us