Sunday, 13 May 2018

To check whether a number is prime or not?

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,...

Sunday, 11 February 2018

Types of user-defined functions in C++

In this post, you will learn more about user-defined functions and how can you use user-defined functions in different ways? Basically, functions are categorized on the basis of return value and arguments, user-defined functions can be categorized as: Function with no argument and no return value Function with no argument but return value Function with argument but no return value Function with...

Wednesday, 31 January 2018

C++ functions

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 block of code that performs some operation.If we want to use a piece of code again and again in the program we wrap that piece of code in the function and use that piece of code in the program by calling it. There are two types of functions in C++. Library function...