C++ program to find a number is prime or not?
Algorithm:
Input = number
set counter=0;
set i=0 to i<=number
if(number%i==0)
counter=counter+1;
i=i+1;
if(counter == 2)
print"number is prime";
else
print "number is not prime";
exit;
Approach to solve:
Input = 5;
number%i=5%1=0
5%2=1
5%3=2
5%4=1
5%5=0
counter=2
so, it will print number is prime.
Input =4
number%i=4%1=0
4%2=0
4%3=1
4%4=0
counter=3
so,...
Popular Posts
-
< bits/stdc++.h> is a master file in c++. It is basically a header file which includes every standard library file. you need this fil...
-
In this article, you will learn about the functions in C++.why and how we use functions. What is a function in C++? A function is a blo...
-
when you use the namespace, your program looks like:- #include<iostream> using namespace std; int main() { cout<<"Hello...
Blog Archive
Blog Search
Powered by Blogger.