Q:

Write a program in c to find prime number or not

0

Write a program in c to  find prime number or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Flowchart:

Algorithm:-

·         Start

·         Read number

·         i=2

·         while(i<n)

·         if(n%i==0)

·         f=1

·         if(f==1)  then print not prime

·         else print prime

·         end

Program:-

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,f;
f=0;
printf("Enter a number");
scanf("%d",&n);
i=2;
while(i<n)
{
if(n%i==0)
{
f=1;
break;
}
i++;
}
if(f==1)
printf("\n not a prime number");
else
printf("\n prime number");
}

Output:-

Enter a number 7

 prime number
Enter a number 8

 not a prime number

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Programming Exercises With Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program in c to find the leap year... >>
<< Write a program in c to find the division of stude...