Question

In: Computer Science

For the prelab assignment, you may not use the if statement nor may you use the...

For the prelab assignment, you may not use the if statement nor may you use the if/else statement. You are to write a program that calculates factorials from 1 up to and including a maximum number given by the user. Because factorials get large quickly, use long unsigned int as the type for the number entered by the user as well as the factorials you are calculating. If the user enters a 0, print an error message. Then ask if the user wishes to continue the program or quit.

Solutions

Expert Solution

C Program:

#include <stdio.h>
int main()
{
//variable declaration
int i,choice;
unsigned long int n;
unsigned long int factorial = 1;
  
printf("Enter a number: ");
scanf("%lu", &n);
  
if(n == 0)
{
//if number is 0,then show error message and ask user to continue
printf("Wrong input.Enter any number to continue.");
scanf("%d", &choice);
main(); //calling main method re-run from first
  
}else
{
//for loop for factorial calculation
for (i=1;i<= n;i++)
{
//calculating factorial
factorial=factorial*i;
  
//printing Factorial of number 'i'
printf("Factorial of %d is %lu ", i, factorial);
}   
}

getch();
}

Output:


Related Solutions

Answer the same problem as the if statement assignment but use the case statement instead. You...
Answer the same problem as the if statement assignment but use the case statement instead. You are working for a company that offers driver licence training and you have been asked to write a script that asks your clients how old they are. If he/she is 16 years old display the message "Please visit our company to take the test!" If he/she is 15 years old display the message "Please take the training with us to learn how to drive!"...
In this assignment. you will determine the probability of several different z-scores. Requirements: You may use...
In this assignment. you will determine the probability of several different z-scores. Requirements: You may use Word, Excel, or write out by hand to complete this assignment. Using the charts available in Top Hat, complete the probabilities of the following: P(x<2.78) P(1.87<x<2.78) P(-2.68<x<0.00) P(0.15<x<1.15) P(-1.33<x<1.33) P(x>1.75) P(x>2.21) P(x<0.56) P(x<-0.56) P(x>1.49) Make sure each answer is numbered All answers must be rounded to four decimal places. You must show your work (if any computation is required) for 100% credit.
In this assignment you are going to use the menu you created in Assignment 1 to...
In this assignment you are going to use the menu you created in Assignment 1 to test both your Double and Integer classes. You should add functionality to the menu to allow you test the add, sub, mul, div functions for instances of both classes You are going to have make a modification to your menu class. Currently it uses an array to hold a fixed amount of menu items. While this may be OK for most applications we want...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a method public static Object removeSecond (): It removes and returns the element just behind the front element. Precondition: The queue has at least two elements. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // Queue.java // demonstrates queue // to run this program: C>java QueueApp //////////////////////////////////////////////////////////////// class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; //-------------------------------------------------------------- public Queue(int s) // constructor {...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a method public static void removeDownTo (long n): It pops all values off the stack down to but not including the first element it sees that is equal to the second parameter. If none are equal, leave the stack empty. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // stack.java // demonstrates stacks //////////////////////////////////////////////////////////////// class StackX { private int maxSize; // size of stack array private long[] stackArray; private int top; //...
you may not use the Python ord() or chr() functions you may not use the Python...
you may not use the Python ord() or chr() functions you may not use the Python ord() or chr() functions you may not use the Python ord() or chr() functions You will write a total of four functions, each of which will take two inputs and return a string: c_encrypt() c_decrypt() vig_encrypt() vig_decrypt() The first argument will be a string containing the plaintext (or clear text) message to be encrypted for the two encrypt functions, and a string containing a...
Question 1 Evaluate the following statement (you may use a diagram): \Economic growth in a large...
Question 1 Evaluate the following statement (you may use a diagram): \Economic growth in a large country may worsen its terms of trade so much that its welfare would be deteriorating after the growth."
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Ex1: Write...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Ex1: Write a program that converts a decimal to binary using a stack. My professor gave me this question to code, is this even possible? if it is can someone code it, in java.
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write method...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write method showStack(): It displays the contents of the stack starting with the first inserted element to the last. The stack would contain the same elements after showStack(). . If for example if to an empty stackx we push(20) then push(30) showStack() would print 20 30 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // stack.java // demonstrates stacks // to run this program: C>java StackApp //////////////////////////////////////////////////////////////// class StackX { private int maxSize;...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write method...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write method showStack(): It displays the contents of the stack starting with the first inserted element to the last. The stack would contain the same elements after showStack(). . If for example if to an empty stackx we push(20) then push(30) showStack() would print 20 30 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // stack.java // demonstrates stacks // to run this program: C>java StackApp //////////////////////////////////////////////////////////////// class StackX { private int maxSize;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT