Question

In: Computer Science

Write a C++ program to read a collective of integer numbers. I f the number is...

Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number

Solutions

Expert Solution

#include<iostream>

using namespace std;

int main()
{
    int n;
    long f = 1;
    
   cout<<"Enter a number between 0(exclusive) and 15(exclusive): ";
    cin>>n;
    
    while(n<=0 || n>=15){
       cout<<"Invalid input"<<endl;
      cout<<"Enter a number between 0(exclusive) and 15(exclusive): ";
       cin>>n;
   }
   
   for(int i  =1;i<=n;i++){
      f = f * i;
   }
   
   cout<<"Factorial of "<<n<<" is "<<f<<endl;
    
    return 0;
}


Related Solutions

Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
C++. Write a program that will read in id numbers and place them in an array.The...
C++. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please enter an...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
Write a C program that asks the user to enter 15 integer numbers and then store them in the array.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].
Write a C++ program that will read in the number of nodes (less than 10) and...
Write a C++ program that will read in the number of nodes (less than 10) and a adjacency relation representing a graph. The program will create an adjacency matrix from the adjacency relation. The program will then print the following items: 1. Print the adjacency matrix 2. Determine if there are any isolated nodes and print them 3. Determine if an Euler path exists Sample run output Please input the number of nodes: 6 Please input the adjacency relation: {(1,2),(1,5),(2,1),(2,3),(3,2),(3,4),(4,3),(4,5),(5,1),(5,4)}...
Write a C++ program that will read in the number of nodes (less than 10) and...
Write a C++ program that will read in the number of nodes (less than 10) and a adjacency relation representing a graph. The program will create an adjacency matrix from the adjacency relation. The program will then print the following items: 1. Print the adjacency matrix 2. Determine if there are any isolated nodes and print them 3. Determine if an Euler path exists Sample run (to make program output more clear, I have put it in boldface): Please input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT