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}
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
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}
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}