In this program we are going to learn how to write
source code for Prime number using while loop
in function.
#include<stdio.h> //header files//
#include<conio.h>
void main()
{ //start the program prime number//
int flag=1,i,no;
clrscr();
printf("Enter any number"); // enter any number//
scanf("%d",&no);
i=2;
while(i<=no/2) //applied While loop for cheking condition//
{
if(no%i==0) // start number is equals to Zero//
{
flag=0;
break; // Break the Loop//
}
i++;
}
if(flag==1) //continue//
{
printf("the number is prime number");
}
else
{
printf("th number .is not prime number");
}
getch();
} // end of program//
The number which divided by 1 and itself only.
rather than this if the number divide by any other number
then we must say it is not a prime number
output is
1).Enter any number17
Number i prime number
2).Enter any number25
Number .is not prime number.
source code for Prime number using while loop
in function.
#include<stdio.h> //header files//
#include<conio.h>
void main()
{ //start the program prime number//
int flag=1,i,no;
clrscr();
printf("Enter any number"); // enter any number//
scanf("%d",&no);
i=2;
while(i<=no/2) //applied While loop for cheking condition//
{
if(no%i==0) // start number is equals to Zero//
{
flag=0;
break; // Break the Loop//
}
i++;
}
if(flag==1) //continue//
{
printf("the number is prime number");
}
else
{
printf("th number .is not prime number");
}
getch();
} // end of program//
The number which divided by 1 and itself only.
rather than this if the number divide by any other number
then we must say it is not a prime number
output is
1).Enter any number17
Number i prime number
2).Enter any number25
Number .is not prime number.
0 comments: