Write a C program that accepts a positive integer number 0

Write a C++ program that accepts a positive integer number > 0 and <= 160 from the
keyboard . The purpose of the program is to do the following :
1. Find and the display all Fibonacci numbers between 1 and that number inclusive.
The Fibonacci sequence is a series of numbers where a number is found by adding up the two
numbers before it. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so
forth. Written as a rule, the expression is xn = xn-1 + xn-2.
2. A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that
number itself. For example:
153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.
12 is not equal to 1*1*1+2*2*2 // 12 is not an Armstrong number.
3. The program will display the factorial of that number. In mathematics, the factorial of a
non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to
n. For example, 5 ! = 5 × 4 × 3 × 2 × 1 = 120. The value of 0! is 1
4. Display the number in reverse order and check to whether or not the number is a
palindrome. For example
If the number entered is 123 then
The reverse of the number is: 321 and the number is not a palindrome
5. Display all palindromes in the given range. For example if the given 115 is the integer then range
is {1, 115} and the output should be
{1 , 2 , 3 ,4 ,5 , 6, 7, 8, 9 , 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111}
The user should be able to repeat the process until the user enters n or N to terminate the
process and the program.

for c++ programming

Solution

#include <iostream>
using namespace std;

int main()
{
// a is first number in series
// b is second number in series
int n,i, a = 0 , b = 1, c;
  
// taking user input
printf(\"Enter a number between 1 and 160 to get fibonacci series : \");
cin >> n;
  
// checking whether number is valid or not
if(n>0 and n<=160)
{
// going as long as the sequence is less than given number
while(b < n)
{
printf(\"%d \",b);
c = b; // saving for help
b = a+b; // adding last two numbers of the sequence
a = c; // making last but one, the last
}
}
else
{
// printing invalid message
printf(\"Invalid number!\");
}
return 0;
}

---------------------------------------------------------------------
SAMPLE OUTPUT

Enter a number between 1 and 160 to get fibonacci series : 160
1 1 2 3 5 8 13 21 34 55 89 144

Enter a number between 1 and 160 to get fibonacci series : 200
Invalid number!

Write a C++ program that accepts a positive integer number > 0 and <= 160 from the keyboard . The purpose of the program is to do the following : 1. Find
Write a C++ program that accepts a positive integer number > 0 and <= 160 from the keyboard . The purpose of the program is to do the following : 1. Find

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site