prime factorization in c

Solutions on MaxInterview for prime factorization in c by the best coders in the world

showing results for - "prime factorization in c"
Fabio
02 Oct 2017
1#include <stdio.h>
2#define MIN 100
3#define MAX 100000
4
5
6int main(){
7    int pdiv=2,j;
8    for (int num=MIN;num<=MAX;num++){
9        printf("The prime factors of %d are:\n",num);
10        j=num;
11        do {
12            
13            if (j%pdiv==0)
14            {
15                
16                printf("%d\n",pdiv);
17                j=j/pdiv;
18            }else
19            {
20               pdiv++; 
21            }
22            
23            
24        }while(j>1);
25        pdiv=2;
26        
27    }
28
29
30
31}
Badis
13 Jan 2019
1#include <stdio.h>
2int main()
3{
4   int i, num, p = 0;
5   printf("Please enter a number: \n");
6   scanf("%d", &num);
7   for(i=1; i<=num; i++)
8   {
9      if(num%i==0)
10      {
11         p++;
12      }
13   }
14   if(p==2)
15   {
16      printf("Entered number is %d "\
17             "and it is a prime number.",num);
18   }
19   else
20   {
21      printf("Entered number is %d "\
22             "and it is not a prime number.",num);
23   }
24}
25
Noé
17 Jul 2018
1/**
2 * C program to find all prime factors of a given number
3 */
4
5#include <stdio.h>
6
7int main()
8{
9    int i, j, num, isPrime;
10
11    /* Input a number from user */
12    printf("Enter any number to print Prime factors: ");
13    scanf("%d", &num);
14
15    printf("All Prime Factors of %d are: \n", num);
16
17    /* Find all Prime factors */
18    for(i=2; i<=num; i++)
19    {
20        /* Check 'i' for factor of num */
21        if(num%i==0)
22        {
23            /* Check 'i' for Prime */
24            isPrime = 1;
25            for(j=2; j<=i/2; j++)
26            {
27                if(i%j==0)
28                {
29                    isPrime = 0;
30                    break;
31                }
32            }
33
34            /* If 'i' is Prime number and factor of num */
35            if(isPrime==1)
36            {
37                printf("%d, ", i);
38            }
39        }
40    }
41
42    return 0;
43}
Niklas
24 Jan 2017
1#include <stdio.h>
2#include <math.h>
3int main()
4{
5     int N;
6     // storing prime number between 2-99
7     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};
8     int prime_index;
9     int i;
10     int power, count, store;
11     printf("\n Prime Factorization of n Factorial. The first number of parameter is prime number and 2nd number is its value.\n");
12     printf("\n\t\tType 0 to exit\n");
13     while (1)
14     {
15          printf("\nNumber : ");
16
17          scanf("%d", &N);
18          if (N == 0)
19          {
20               printf("\nThanks for using our component\n");
21               return 0;
22          }
23          if (N<2 | N> 99)
24          {
25               printf("\nType a number between 2-99\n");
26               continue;
27          }
28          for (i = 0; N >= p_arr[i]; i++)
29          {
30               prime_index = i;
31          }
32
33          printf("Factorial : ");
34          for (i = 0; i <= prime_index; i++)
35          {
36               count = 0;
37               power = 1;
38
39               for (store = N / pow(p_arr[i], power); store != 0; power++, store = N / pow(p_arr[i], power))
40               {
41                    count = count + store;
42               }
43
44               if (count > 0)
45               {
46                    if (i == prime_index)
47                    {
48                         printf("(%d,%d)", p_arr[i], count);
49                    }
50                    else
51                    {
52                         printf("(%d,%d) * ", p_arr[i], count);
53                    }
54               }
55          }
56          printf("\n");
57     }
58
59     return 0;
60}
queries leading to this page
c program weather a given number is prime ir notprime number program in c languageprime number or not in cprint prime numbers on cc program that dedects primes with araysc program to check if a number is prime number or notc primehow to find the prime factors in cc program for prime factorization of a numberprime factorization algorithm c 2b 2bprinting prime factors in chow to find prime numbers in c 23 23seperate number in prime factor in ccode to check if a number is a prime number in cpoc programming to find prime numberisprime chow to check if number is prime in cprime numbers cwhat is a prime number in cc program prime factorization c how to prime numbershow to find f a number is prime or not in cwap in c to find prime numbersc function return prime factorprime numbers c program printc prime factorizationc programming prime number to print prime numbers in cprime factorization of 1c code to check whether number is prime or notc program to print prime numbersprime numbers check in cgenerating prime number in cis prime c functionc program to check if number is prime or notprime number check code in chow to get prime number in cdefine and use isprime function to check whether number is prime or notprint all prime factors of a number prime factor of a given number in cprime or not c programprint out the prime factors of a numberprogram for prime in cc program function that returns 1 if a number is a prime number 2c otherwise 0primary number in c code without inputprime number logicfind all prime factors of a number in cwap to check prime numberfine prime number in c prime function in cprime factorization c fastprime number in c language code factorize primes in cprimenumber codewrite c program to find whether the given number is a prime number check whether a given number is a prime number or not in cfind prime factors in cprime number cprime numver c ofstrobogrammatic prime number in cc program to check prime number using for loopcode to print prime numbers in cprime number function c print prime numbers in cprime numbers in cprogram to find prime factors of a numberwrite a program to determine whether a number is prime or not using break statement a prime number is one 2c which is divisible only by 1 or itself c program prime number for loopcode program for prime number in cprime numbers from 1 to 100 in ccheck whether prime or notprime factor algorithm in cfind prime numbers in c 5csimplest logic for prime numberprime number program n cprime number test c prime numbers program in cfind number prime ot not in ccode for checking prime numberc code to check prime numberprime number in c programmingnot program in cis prime function in cc prime number functionprime factors cprime numbers c primitive functionsc prime number programfunction is prime cprime factorization of 10code for finding prime numbersum of factorial series in chow to find a prime number in cfinding prime number in cprime factors in cprime number code ccode for prime numbers in cwrite a program in c to check whether the given number is prime number c program to print prime factors of a number in cc calculate primeprime number c codecheck if a number is prime codeprime c programprime number series program in chow to heck if an input input is primecode to find prime numberis prime number in cprime number using cc program print prime numberswhat are prime numbers in c whether the number is prime or not cwap to check if a number is prime or notprime factor program in chow to check if a number is prime cprime number program codeverify prime number c 22primes 7cfactor c 22primes numbers cc prime numbersc language isprimeprime number c program totalc program for prime numberwrite a program to find the given number is prime or notcheck whether a number is prime or not c programhow to find prime numbers in cprime digits in a given number in cprime number with c programmingprime no codenearly prime number in cprime factor of a given number in cprime factorization program in c using pthreadprograms regarding prime factorizationc language prime numberc program to find prime numbersprime number checker c c code for prime numberhow to write primary number in codehow to generate the prime numbers in chow to factorise when c is a prime numberprogram to find prime number in simple codehow to find all prime factors and frequencies in c 2b 2bis prime function in c with out using flagscheck if a number is prime cprime no logicprime number in cisprime function csimple prime number program in cprint prime factors of a number in cwrite a program for prime numbersc program for prime factors of a numberc program prime numberscheck if num is prime cprime or not in cc program prime numberprime number logic in cprime no program in ccheck for prime number in cprime number program in c 27check if a number is prime in cprogram to find whether a number is primegenerate prime numbers in cc program to find prime factors of a number100 prime numbers in cis prime c programc is prime functioncheck if prime or not cprime factorization of a number in cwhat is prime numbers c write a c program to show the prime factor of a given number code to find prime nubercheck prime numberfind prime factors of a number in clogic for code of prime number c language 5dfind prime factorizationc program in prime numberprime factorization using sieve in cprime cprime number condition in cprogram to get prime factors of a numberwap to find whether the number is prime or notprime number in program cprime numbers code in cfunction for a prime number cwrite a function that takes an integer number as an input argument and return if the number is a prime number or not 28use any programming language 29write a program to test whether an integer 28greater than 2 29 entered by the user is a prime or not prime number coding logicis it prime number cprime number in c with functionprogram to find nuber is prime or nitcode to check if a number is primeprimary number in c codeprime factor of number c programmingprime number in clogic for primeprime factor in cc language prime factorsprint all prime numbers in clogic of prime numberprint n prime numbers in cprime factorization method in cprimen number in cwrite a c program to enter any number and print its prime factors prime number program in chow to find prime factors of number in cprime factor program of a given numberin cchack prime number in chow to get prime numbers cprime factorization c programprime factor or not in chow to find out if a numbe ris prime in csyntax for prime number in cprime no in cprime numbers c programis prime number cis prime function chow to find out prime numbers in cwrite a c program to find out prime factor of given numberprime no in c languagefind prime number programhow to get a prime number in cprime factorization of a number c 2b 2ba program in c that check prime numberprogram to find prime factors of a number in cwrite a program to find whether a given number is prime or not how to make primes in cc program to determine prime numbermake a prime number in cc program code for primeformula for prime numbers in cc prime mathprime numbers with cprogram to check for prime number in cchecking prime number in cwhat is the prime factorization of 14checking if a number is prime in cprinting prime numbers in cc check for prime numberhow to prime number in cwrite a function to obtain prime factors of given number in cprime or not in c programfactorize a number to the power of primes in c 2b 2bprime factor program of a given number in cc prime number prgoamhow to print prime numbers in cprime numbers formula in cc programs code for primeprime no logicfinding the prime factors of a number chow to compute prime number in cc code prime numberprogram to check if a number is prime or not in cfind prime number in clogic to find prime number in cwap to find prime factors of a numberthree ways of checking prime in cprime no or composite cryptography program in cfinding prime numbers chow to find prime factorisation of a number in cprime number using break in c explanationcode to generate prime numbers in cc program to check prime numberprime chec in ccheck prime cprogram for prime number in cprime number codeprimenumber in cprogram for prime factors in cwrite a program to display prime numberscode for prime numberc program to find prime numberprime factorization in cc code for prime numbersc program to find if a number is prime square rootprime number generator cc in prime numberfind if no is prime cis prime cprime no cc code to find prime numberprime factorizationc prime factorsc how to check if a number is primeprime number c programprime program in cc how to find prime numberprime number algorithm in cprogram that figures out if a number is prime in cprimary number cfunction to find out if a number is prime in cprime no program in cwhat is prime factor cfind c program for prime factorshow to check the numbe rid prime in cprint all prime factors of a given numberleast prime factor of a given number in cfind prime number c programc how to generate prime numbersprogram to find prime numberis prime in cprint prime number in cc program to print prime factors of a numberprime factoring in cprime number in ccheck prime number using cprime number range program in cgeneration of prime numbers in cc prime numberprogram to print prime number in cprime in chow to find prime factors of a number in chow to check if a number is prime in cprime factors of a number in c using functionfind prime in cprime numbers codecalculate prime number in cprime number code in ccheck if number is prime in ccheck prime number in cmonolithic c program to find prime numbersprime chec kin ccode for prime number in cprint the prime numbers in cprime factors of n in cc programming prime numbersprime number in c my sirgprime factorization of factorials using cprime factors of a number in cprogram of prime number in cprime number finder in cloop 26 if structure to test whether an input number is prime or composite prime numbers programprogram to find prime numbersprint check wherter a no is prime or notcheck prime numbers in chow to find prime number in chow to find a prime factors in cprimer number cis number prime cprime no codeprime logic in cprime numeber code in cc language check whether primehow to check prime number in chow to find the prime factors of a number in cprime factorization in c