From 2ef63dddbc23ac62d69bf136803e5aaeedbca61c Mon Sep 17 00:00:00 2001 From: Raya513 <64854191+Raya513@users.noreply.github.com> Date: Mon, 4 Oct 2021 16:42:44 +0530 Subject: [PATCH 1/3] Create Nth prime number.c --- Nth prime number.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Nth prime number.c diff --git a/Nth prime number.c b/Nth prime number.c new file mode 100644 index 0000000..be567f8 --- /dev/null +++ b/Nth prime number.c @@ -0,0 +1,41 @@ + +#include +#include +void prime(int m); +void main() +{ + int n; + printf("Enter nth="); + scanf("%d",&n); + prime(n); +} +void prime(int n) +{ + int count=1,j,i,flag; + if(n==1) + { + printf("prime no is 2 "); + return; + } + for( j=3;j<=10000;j++) + { + for(i=2,flag=0;i<=sqrt(j);i++) + { + if(j%i==0) + { + flag=1; + break; + } + } + if(flag==0) + { + count++; + } + if(count==n) + { + printf("Prime number=%d\n",j); + break;//since its within the j loop without the break statement + //it keeps printing up until the next prime number + } + } +} From 1af97e1d861c42e6b9239fccc96f51d508ff2821 Mon Sep 17 00:00:00 2001 From: Raya513 <64854191+Raya513@users.noreply.github.com> Date: Mon, 4 Oct 2021 16:44:37 +0530 Subject: [PATCH 2/3] Delete Nth prime number.c --- Nth prime number.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 Nth prime number.c diff --git a/Nth prime number.c b/Nth prime number.c deleted file mode 100644 index be567f8..0000000 --- a/Nth prime number.c +++ /dev/null @@ -1,41 +0,0 @@ - -#include -#include -void prime(int m); -void main() -{ - int n; - printf("Enter nth="); - scanf("%d",&n); - prime(n); -} -void prime(int n) -{ - int count=1,j,i,flag; - if(n==1) - { - printf("prime no is 2 "); - return; - } - for( j=3;j<=10000;j++) - { - for(i=2,flag=0;i<=sqrt(j);i++) - { - if(j%i==0) - { - flag=1; - break; - } - } - if(flag==0) - { - count++; - } - if(count==n) - { - printf("Prime number=%d\n",j); - break;//since its within the j loop without the break statement - //it keeps printing up until the next prime number - } - } -} From 7ab32873e19f55cdd5273e7dbce105705875a07c Mon Sep 17 00:00:00 2001 From: Raya513 <64854191+Raya513@users.noreply.github.com> Date: Mon, 4 Oct 2021 16:45:11 +0530 Subject: [PATCH 3/3] Create Nth prime number.c --- .../Binary_Search/Nth prime number.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Arrays/Searching/Binary_Search/Nth prime number.c diff --git a/Arrays/Searching/Binary_Search/Nth prime number.c b/Arrays/Searching/Binary_Search/Nth prime number.c new file mode 100644 index 0000000..be567f8 --- /dev/null +++ b/Arrays/Searching/Binary_Search/Nth prime number.c @@ -0,0 +1,41 @@ + +#include +#include +void prime(int m); +void main() +{ + int n; + printf("Enter nth="); + scanf("%d",&n); + prime(n); +} +void prime(int n) +{ + int count=1,j,i,flag; + if(n==1) + { + printf("prime no is 2 "); + return; + } + for( j=3;j<=10000;j++) + { + for(i=2,flag=0;i<=sqrt(j);i++) + { + if(j%i==0) + { + flag=1; + break; + } + } + if(flag==0) + { + count++; + } + if(count==n) + { + printf("Prime number=%d\n",j); + break;//since its within the j loop without the break statement + //it keeps printing up until the next prime number + } + } +}