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.
- Declaring Variable as required.
- Using required function or statements.
- 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;
}
}