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
Program to check prime or composite using break statement in C
2:36 PM
Break Statement in C
,
C Programs
,
OldQuestionSolution2015C
,
Prime or Composite in C
,
WAP to find weather the entered no is prime or composite
Edit
0 comments:
Post a Comment