Answers for "write c program to find factorial of a number using functions -- find the time complexity of the code."

C
2

factorial c program using for loop

#include<stdio.h>
int main(){
  int i,f=1,num;
 
  printf("Enter a number: ");
  scanf("%d",&num);
 
  for(i=1;i<=num;i++)
      f=f*i;
 
  printf("Factorial of %d is: %d",num,f);
  return 0;
}
Posted by: Guest on January-10-2021
-1

prime factorization of factorials using C

#include <stdio.h>
#include <math.h>
int main()
{
     int N;
     // storing prime number between 2-99
     int p_arr[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
     int prime_index;
     int i;
     int power, count, store;
     printf("n Prime Factorization of n Factorial. The first number of parameter is prime number and 2nd number is its value.n");
     printf("nttType 0 to exitn");
     while (1)
     {
          printf("nNumber : ");

          scanf("%d", &N);
          if (N == 0)
          {
               printf("nThanks for using our componentn");
               return 0;
          }
          if (N<2 | N> 99)
          {
               printf("nType a number between 2-99n");
               continue;
          }
          for (i = 0; N >= p_arr[i]; i++)
          {
               prime_index = i;
          }

          printf("Factorial : ");
          for (i = 0; i <= prime_index; i++)
          {
               count = 0;
               power = 1;

               for (store = N / pow(p_arr[i], power); store != 0; power++, store = N / pow(p_arr[i], power))
               {
                    count = count + store;
               }

               if (count > 0)
               {
                    if (i == prime_index)
                    {
                         printf("(%d,%d)", p_arr[i], count);
                    }
                    else
                    {
                         printf("(%d,%d) * ", p_arr[i], count);
                    }
               }
          }
          printf("n");
     }

     return 0;
}
Posted by: Guest on July-04-2021

Code answers related to "write c program to find factorial of a number using functions -- find the time complexity of the code."

Code answers related to "C"

Browse Popular Code Answers by Language