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.

Solution

1.answer

#include<stdio.h>

int fib(int n)

{

if (n <= 1)

return n;

return fib(n-1) + fib(n-2);

}

int main ()

{

int n = 9;

printf(\"%d\", fib(n));

getchar();

return 0;

}

2answer.

3answer:

#include <stdio.h>

#include <conio.h>

int main()

{

int N, nFactorial, counter;

printf(\"Enter a number for factorial calculation \ \");

scanf(\"%d\",&N);

for(counter = 1, nFactorial = 1; counter <= N; counter++){ nFactorial = nFactorial * counter; }

printf(\"Factorial of %d is %d\", N, nFactorial);

getch();

return 0;

}

4Answer

#include <stdio.h>

int reversDigits(int num)

{

int rev_num = 0;

while(num > 0)

{

rev_num = rev_num*10 + num%10; num = num/10;

}

return rev_num;

}

int main()

{

int num = 4562;

printf(\"Reverse of no. is %d\", reversDigits(num));

getchar();

return 0;

}

5answer:

#include<iostream>

using namespace std;

// A function to check if n is palindrome

int isPalindrome(int n)

{

int rev = 0;

for (int i = n; i > 0; i /= 10) rev = rev*10 + i%10;

return (n==rev);

}

void countPal(int min, int max)

{

for (int i = min; i <= max; i++)

if (isPalindrome(i)) cout << i << \" \";

}

int main()

{

countPal(100, 2000);

return 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
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