Question

KAM5 Write a function unsigned long long int factorial(int num) to compute the factorial of a number. The factorial of a numb

C programming

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

NOTE: IF YOU HAVE ANY DOUBTS ASK IN COMMENT SECTION. PLEASE GIVE ME UP VOTE. THNAK YOU.

CODE:

#include <stdio.h>

unsigned long long int factorial(int num){
if(num==1){
return 1;
}
return num*factorial(num-1);
}

int main()
{
printf("%llu\n",factorial(5));
printf("%llu\n",factorial(20));
return 0;
}

SCREENSHOT :

main.c 1 #include <stdio.h> 3 unsigned long long int factorial(int num) { if(num=-1){ return 1; 600 vouw return num factorial

OUTPUT :

input 120 2432902008176640000 ... Program finished with exit code 0 Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
C programming KAM5 Write a function unsigned long long int factorial(int num) to compute the factorial...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 10.11 (Left Shifting Integers ) Left shifting an unsigned int by 1 bit is equivalent to...

    10.11 (Left Shifting Integers ) Left shifting an unsigned int by 1 bit is equivalent to multiplying the value by 2. Write function power2 that takes two integer arguments number and pow and calculates number * 2pow. You should declare pow as an unsigned integer , but remember that the result may be a negative value . Use the shift operator to calculate the result. Print the values as integers and as bits . Assume that an integer is of...

  • The language has to be in C program 1. (a) rite a function, int factorial (int...

    The language has to be in C program 1. (a) rite a function, int factorial (int n), which returns n (the factorial of n, i e. 1 x2 x3 x...xn.) (b) Using int factorial (int n) above, write a program to compute 2. We want to find one of the roots of a cubic equation given by which is between 0 and 1 by an iterative method. Modify the equation above to 1 x Start with an appropriate initial value...

  • (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n)...

    (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n) { } int quadrant(int x, int y) { } int num_occurrences_of_digit(long num, int digit) { return 0; } 3.1 int sum_of_cubes(int n) This function should return the sum of the cubes of the first n integers. For example, if n is 4, it should return 13 +23+ 39 +4°. There is a simple formula for the result: 3x = ((n + 1)) = +...

  • rite a c funetion to find factorial of a nunbez. The factorial of a positive nunber...

    rite a c funetion to find factorial of a nunbez. The factorial of a positive nunber n is given by: factorial of n (n!)1*23*4....n copy the following code, then finish the progran <stdio.h> #include Define a function factorial to return the factorial of n (n!) long int factorial (int n) // your code int mainO int n; printf ("please input n:") scanf ("%d", &n); printf (d! %1dn, n, factorial (n)) return 0

  • Write a C function named  f such that … the prototype of function  f is … unsigned long...

    Write a C function named  f such that … the prototype of function  f is … unsigned long int f ( unsigned long int X, unsigned long int Y ) function  f returns … the nonnegative integer  Z  such that   X 2  +   Y 2  =   Z 2  if such a nonnegative integer  Z  exists zero if there is no nonnegative integer  Z  such that   X 2  +   Y 2  =   Z 2  Example 1 If   X = 3  and   Y = 4 ...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • Write a program in C++ that implements a function // Precondition: num >= 0 int rotateUp(int...

    Write a program in C++ that implements a function // Precondition: num >= 0 int rotateUp(int num); which produces a new integer with each digit replaced with (digit+1), and 9 replaced with 0, because we don’t have digit 10: rotateUp(5) == 6 rotateUp(17) == 28 rotateUp(126) == 237 rotateUp(5091) == 6102 rotateUp(9911) == 22 // technically, more like 0022 The program should have a main function that tests the function. Example Output: Enter a number: 901 12

  • 2. Stacks and Queues Reinernber: Consider the following function: void systery( int num) { int current:...

    2. Stacks and Queues Reinernber: Consider the following function: void systery( int num) { int current: /* create Stack stk and Queue que / Stacks: the function push places the given parameter on the top of the stack, the function pop removes and returns the top of the stack, and the function empty returns true (i.c., 1) if the stack is empty or false (i.e., 0) otherwise. Queues: the function insert places the given parameter on the end of the...

  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • I am having problems getting the insertion sort function to output in descending order. Also, the...

    I am having problems getting the insertion sort function to output in descending order. Also, the initialize array function is not being called when I test it in the main function. I am wondering why it prints out the original array instead of initializing. Thank you. #include <stdio.h> void print_array(int *array, int length){ int i; for(i=0; i<length;i++) printf("%d"",",array[i]); printf("\n"); } void initialize_array(int *array, int length){ int i; for(i=0, i<length; i++;){ if (i%2 ==0) array[i]= 5; else array[i]= 0; } }...

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
ADVERTISEMENT