Monday, January 17, 2022

C-C++ Programming Language Prime Number Finder Codes

We wish everyone a good day. In this article, we will tell you how to write prime number finding codes in the C-C++ programming language. We wish you good coding...




C Programming Prime Number Finder Codes

Prime Number Query Codes:

#include <stdio.h>
#include <conio.h>
int main ()
{
int sayi;
int j,k,l,m;
printf("Enter a number:\n");
scanf("%d",&sayi);
for(int i=2; i<sayi; i++){
if(sayi%i==0){
printf("Number is not prime\n");
break;
} }
j=sayi;
for(int k=2; k<j; k++)
{
if(j%k==0){
k=2;
j=j-1; 
}}
l=sayi+1;
m=sayi+1;
for(int k=2; k<l; k++)
{
if(l%k==0){
k=2;
l=l+1; 
m=m+1;
}}
if(j==sayi)
{ printf("Number is prime.\n");
}
else
if(l-sayi==sayi-j){
printf("%d prime numbers closest to %d and %d ",sayi,m,j);
}
else
if(l-sayi<sayi-j){
printf("%d prime number closest to %d ",sayi,m);
}
else printf("%d prime number closest to %d ",sayi,j);
getch();
return 0; }


Thanks.

Source : www.mmsrn.com/kendisine-en-yakin-asal-sayiyi-bulan-c-programi-versiyon-1-2/

0 comments:

Post a Comment