General Simple level interview programs
In basic freshers level interview, generally the interviewer prefers to ask some simple school level programs for beginning the interview and making the candidate confident. So it is very important to have a look at some of the basic programs before hand and you should be able to write program based on these questions in given time slot. I will be telling some of these questions in this blog and I will keep updating the questions and adding more and more basic level interview questions. So lets begin…
1. Fibonacci series
It is the most loved question of interviewers and first of all you should be knowing what a fibonacci series is:
It is basically series where numbers follow a pattern i.e number would be the sum of previous two numbers and 0 and 1 are the beginning of the series. So the series look something like this:
0 1 1 2 3 5 8 13 21 ...
There are two approaches to solve this problem:
- Iterative
The basic idea of this approach is to keep track of two variables and generate the third variable by adding previous two variables and after one adding assigning first variable with second value and second variable with sum like this:
- Recursive
The approach here is to recursively calling same function and adding previous two values like this:
2. Factorial
Factorial of a number is the product of number with previous numbers upto 1.
e.g 5! = 5 * 4 * 3 * 2 * 1 = 120
Again there are two approaches for this one too i.e
- Iterative
- Recursive
3. Prime Numbers
A prime number is a number that is divisible by itself and by 1.
e.g 2,3,5,7,11,13 ...
4. Reverse a number
A number can be reversed by the approach of dividing the number by 10 and taking its reminder:
123 = 3 * (10 ^ 0) + 2 * (10 ^ 1) + 1 * (10 ^ 2)
4. Palindrome
A palindrome number is a number that is same after reversing the digits.
e.g 121 is a palindrome number
123 is not a palindrome number
Approach used to solve this is very simple:
- Store the given number in a temporary variable
- Reverse the number
- Compare with given number
6. Armstrong Number
Armstrong number is a number that is the sum of cube of digits of that number.
e.g 153 is a armstrong number as 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
7. Swapping numbers
There are 4 ways of swapping a number:
- By third variable and direct value
- By third variable and referencing value
- Without third variable using + and -
- Without third variable using * and /
8. Sum of digits
The approach is same as reversing a number and the only difference is that you have to just add the reminders like this:
e.g 153 = 1 + 5 + 3 = 8
All the cpp programs are added to github here :
I will be keep on adding more questions in this blog post, so do follow me and if you like the blog, hit that clap icon and share it with your fiends.