Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, December 5, 2014

Program to find input number is prime or not using do while loop in C.


prime number


Code Box
-----------------------------------------------------

/*Program to find input number is prime or not*/

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,c;
c=0; //counter
clrscr();

printf("\nEnter any number:");
scanf("%d",&num);

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");

i=2;
/*start from 2 because every number is divisible by 1 */

/*Prime finder */
do
{
if(num%i==0)
{
c=1;
}
i++;
}while(i<num) ;

/*Prime checker */
if(c==0)
{
printf("\n%d is prime",num);
}
else{
printf("\n%d is not a prime",num);
}

printf("\n------------------------------");

getch();
}



No comments: