Prime Number
Goal:- Print all Prime Numbers in a Given Range.
Method-Used:- Recursion
Explanation:- Prime Number- Numbers which are only divisible by 1 and itself,known as Prime Numbers. All prime Numbers are greater than 1.
Example:- Between 1 to 10- 2,3,5,7 are prime Numbers.
Given Program display all the Prime numbers between two numbers that are user inputs. In the program prime function checks whether a number is prime or not.
Program:-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int prime(int m)
{
int n=2;
while(n<=m/2)
{
if(m%n==0)
return 0;
else
n++;
}
return 1;
}
int main()
{
int a,b,k,i;
printf("\n\tEnter the range{a to b(a>b)} of prime Numbers:-\n");
printf("\n\tEnter starting Number(a):");
scanf("%d",&a);
printf("\n\tEnter Last No.(b):");
scanf("%d",&b);
printf("\n");
if(a>b)
{
printf("Invalid Input(a<b)");
}
else
{
for(i=a;i<b;i++)
{
k=prime(i);
if(k==1)
printf("\t%d",i);
}
}
getch();
}
Output:-
If you want to share more information about topic discussed above or find anything incorrect Please do comments.
0 comments:
Post a Comment