WAP to determine whether the Number is Prime or Not by using while and if Statement

C break Statement
Break Statement:
There are many situations where we want to jump out of a loop instantly. The keyword break allows us to do this. When break is encountered inside any loop, control automatically passes to the first statement after the loop. So Let us understand the break statement with the help of Program :-

Statement of C Program: This Program accepts a number and determined whether the number is Prime or not.

Prime Number:
A Prime number is one, which is divisible by 1 or itself.  Ex: 3 , 5 , 7 , 11 , 13 , 17 , 23 , 19 etc.

#include<stdio.h>
#include<conio.h>
void main()
{
int a , b ;
clrscr();

printf(" Enter the value of a\n");
scanf("%d" , &a);

b = 2;
while( b <= a-1 )
{
if(a % b == 0)
{
printf(" Entered Number is not Prime\n");
break;
}
b = b + 1;                                                   /*   b++     or    b += 1   */
}
if(b = a)
{
printf(" Prime Number\n");
}
getch();
}

Output1:
Enter the value of a
7
Prime Number

Output2:
Enter the value of a
9
Entered Number is not Prime

Explanation:
  • In the above Program, if the condition { i.e a % b } turns out to be zero, then the message " Entered number is not Prime " is printed and after that the break statement encountered which causes control out of while loop.
  • If the condition { i.e b == a } is true, then the message " Prime Number " is printed.
                                                                      
                                                                    That's All

0 Response to "WAP to determine whether the Number is Prime or Not by using while and if Statement"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag