Saturday, 14 October 2017

Practical-8

PRACTICAL- 8
Aim of the practical:-
Write a program (WAP) to enter any number and check that whether it is a Prime number or Composite number.

Header files used:-
#include <iostream.h>
#include <stdlib.h>
Conditional statements/Loops used:-
i.                   If– else statement
ii.                 while loop/for loop
Prime  & Composite Number:
A prime number is a natural number greater than 1 which has no positive divisors other than 1 and itself.
A natural number that is greater than 1 and that is not a prime number is called a Composite number.
Procedures followed:-
The user will be asked to enter any number. The number entered by the user will be divided with all numbers starting from 1 up to the number itself to find its divisors, using a for loop and an if statement. By comparing the number of divisors found with 2 using an if-else statement we can find weather it is a prime or composite number.

Coding:-

No comments:

Post a Comment