C Program to Generate Prime Factor

Definition of Prime Factor from Wikipedia: In number theory, the prime factors of a positive integer are the prime numbers that divide that integer exactly. The process of finding these numbers is called integer factorization, or prime factorization.

Example: Prime factors of 288 are:
288 = 2 x 2 x 2 x 2 x 2 x 3 x 3

Here is a you tube video for you that will help you to understand prime factorization.



Now we are moving towards a C program that will find the prime factors of a number.


C Program to Find Prime Factors:


#include <stdio.h>

int main()
{
    
    int number,div;    
    printf("Enter a number to know its prime factor: ");    
    scanf("%d",&number);
    
    printf("\nThe prime factors of %d are: \n\n",number);
    
    div = 2;
    
    while(number!=0){
        if(number%div!=0)
            div = div + 1;
        else {
            number = number / div;
            printf("%d ",div);
            if(number==1)
                break;
        }
    }
    return 0;
}

9 comments :

  1. nice programming, Can you please provide links where I can hone my programming skills as a beginner.

    ReplyDelete
    Replies
    1. http://www.mycodeschool.com/ is a good site for beginners.

      Delete
  2. Best Method... (h)

    ReplyDelete
  3. Can you pls xplain d program prime factor

    ReplyDelete
  4. Prime number program in C++

    A prime number is a natural number which is greater than 1 and these numbers are only divisible by 1 and itself number. In programming point of view, we check condition number is divisible by other number or not except 1 and number itself. If number is not divisible by other number than that number is prime number.

    ReplyDelete

Spam comments will be deleted. :)

 
Loading...
TOP