C program to Check Prime Numbers | Checking Prime Numbers - Anna University Multiple Choice Questions

C program to Check Prime Numbers | Checking Prime Numbers

Aim:
                To write a C program to check the prime number.

Algorithm
  1. Start the program
  2. Read the number ‘num’ from the user.
  3. For all i>num/2 divide the number by i.
  4. If the number is divisible by any other numbers then that number is not a prime number.
  5. If the number is not divisible by any other numbers then that number is a prime number.
  6. Display the result
  7. Stop the Program
 C Program – checking Prime Number :

#include<stdio.h>
#include<conio.h>
Void main()
{
int num,I;
clrscr();
printf(“\nEnter a number”);
scanf(“%d”,&num);
for(i=2;i<=num/2;i++)
{
If(num % i==0)
Break;
}
If (i>num/2)
Printf(“the given number %d is prime”,num);
else
printf(“The given number %d is not prime”,num);
getch();
}

Output - checking Prime Number

Enter a number 56
The given number 56 is not prime
Enter a number 3
The given number 3 is prime
 
 --------------------------------------------------------------------------------------------------------------
 
C program to Check Prime Numbers-Checking Prime Numbers-C program to find prime numbers -Write a program to find prime numbers- C programs- Write a c program to find the given number is prime or not

No comments:

Post a Comment