Program to check prime or composite using break statement in C

WAP to check whether the entered number is prime or composite which shows the break statement as well.
#BIT_FirstSem_2015_10No_5Marks_Solution
 /* WAP to check weather the entered number is prime or not */
#include<stdio.h>
int main()
{
    int i,flag=0,num;
    printf("Enter a number:");
    scanf("%d",&num);
    for(i=2;i<=(num/2);i++)
    {
        if(num%i==0)   
            {
            flag=1;
            break;
            }
   }
    if(flag==0)
    printf("Prime Number!");
    else
    printf("\n Composite Number");
    return 0;
}

Output : 










Output1:









I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment