Question

1. Write a program to print all natural numbers from 1 to n. - using while...


1. Write a program to print all natural numbers from 1 to n. - using while loop 

2. Write a program to print all natural numbers in reverse (from n to 1). - using loop 

3. Write a program to print all alphabets from a to z. - using while loop 

4. Write a program to print all even numbers between 1 to 100. - using for loop 

5. Write a program to find sum of all odd numbers between 1 to n. 

6. Write a program to print multiplication table of any number. 

7. Write program to find power of a number using for loop. Y = nx 

8. Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as: n! = n·(n-1)·(n-2)·.……·3·2·1. The factorial of 0 is 1. If a number is negative, factorial does not exist and this program should display error message. Sample output dialogues should look like these: 

Enter an integer: -5

ERROR!!! Tactorial of a negative number doesn't exist 

Enter an integer: 10 

Factorial = 3628800

3 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

8)

#include
using namespace std;
int factorial(int n)
{
if(n==0)
return 1;
else
return n*factorial(n-1);
}
int main()
{

cout<<"Enter an integer: ";
int n;
cin>>n;
if(n<0)
cout<<"Error!!! Factorial of a negative number doesn't exist\n";
else
cout<<"Factorial = "< return 0;
}

Add a comment
Know the answer?
Add Answer to:
1. Write a program to print all natural numbers from 1 to n. - using while...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT