Monday 27 August 2012

While loop | c program while loop | examples with source code

 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.
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: