/* Prime Number using while loop */
#include<stdio.h>
int main()
{
int a,i,f;
printf("Enter a number: ");
scanf("%d",&a);
f=0;
i=2;
while(i <= a/2)
{
if(a%i == 0)
{
f=1;
break;
}
i++;
}
if(f==0)
printf("Prime Number")
else
printf("Not Prime Number");
return 0;
}
Related Post
Prime number using for loop
http://cbasicprogram.blogspot.in/2012/03/prime-number-using-for-loop.html
#include<stdio.h>
int main()
{
int a,i,f;
printf("Enter a number: ");
scanf("%d",&a);
f=0;
i=2;
while(i <= a/2)
{
if(a%i == 0)
{
f=1;
break;
}
i++;
}
if(f==0)
printf("Prime Number")
else
printf("Not Prime Number");
return 0;
}
Related Post
Prime number using for loop
http://cbasicprogram.blogspot.in/2012/03/prime-number-using-for-loop.html
thanks very much
ReplyDeleteAttention everyone, the file provided above is not working. I have been looking for the working file and finally found it.
Delete✔️Click Here To Download http://gestyy.com/e0GAyS
✔️Click Here To Download
✔️Click Here To Download http://exe.io/XONVsO6l
✔️Click Here To Download
✔️Click Here To Download
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Mn.
..
.
.
.
..
.
.
.
.
.
.
.
.
.
.
..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.ds
.
.
.
.sdcccxxx
thnks plz tell me another logic of prime number
ReplyDelete#include
Delete#include
void main()
{
int i,num;
printf("Enter a Number-\n");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("Not a Prime Number!\n");
break;
}
i++;
}
if(i==num)
printf("Prime Number!\n");
getch();
}
if num=2
Deletethen
while(i<=num-1)
2<=1..this condition is false
then how it proceeds to prime number ???
tq love u
ReplyDeleteWhy there is num-1 in the while loop plz explain
Deletebcz prime no. is a no. which is divided by 1 and itself
Deletelove u too
Deletethank u
ReplyDelete#include
ReplyDeleteint main()
{
int n,i;
printf("Type the number:");
scanf("%d",&n);
i=2;
while (i<(n/2))
{
if (n%i==0)
{
printf("%d is not a Prime Number",n);
break;
}
i=i+1;
}
if (i>=(n/2))
{
printf("%d is a Prime Number",n);
}
return 0;
}
Please Flow Chart ...
Deletethis is not acceptible using number 3
ReplyDeletealso for 2
DeleteWhy a/2 i cant understand that please tell me
ReplyDeletebcoz to check if a number is divisible, we just need to check to its half.
Deletelike 11, if you can not divide it from 2-5 it is prime, 6-10 are not going it divide it anyway
please anyone give output of this program
Deleteit's defecult how can i learn
ReplyDelete#include
ReplyDeleteusing namespace std;
int main()
{
int start=1;
int num;
cout<<"Enter the number to check if it's prime or not? "<>num;
int counter=0;
while(start<=num)
{
if(num%start==0)
{
counter++;
}
start++;
}
if(counter==2) //if number has only 2 divisors( 1 and number itself)
cout<<num<<" is Prime number"<<endl;
else
cout<<"Not a prime number"<<endl;
system("pause");
}
can anyone tell what is function of counter in this function
DeleteI want to buy your blog please text me or call me hitesh.xc@gmail.com 8076671483
ReplyDeletehttps://maytinhtrananh.vn/sua-may-tinh-may-in.html
ReplyDeletehttps://phalebinhminh.com
Tranh dán tường/
ReplyDeleteTranh treo tường 3D
In UV
I have found amazing article on prime number program in C with different examples with outputs like while, for loops, 1-n, nth numbers and between two intervals.
ReplyDeleteLaravel Blade While Loop Example
ReplyDeleteobinema Curtis Bethea https://wakelet.com/wake/deCqg4DyhhXvugukTJer0
ReplyDeletescisoggata
UcunccoiOmaumi Sharon Cook Express VPN
ReplyDeleteYour Uninstaller
ReiBoot Pro
ligangtergder