C Program for Prime Factorization

Prime Factorization

     Before going to know about prime factorization,we must have an idea about Prime Numbers,Factors,Factorization

Prime Number

A Prime Number is an integer that can be only divisible by 1 and itself.
   Ex:2,3,5,7,11.............

Factors

The numbers which evenly divides the given number are called factors of given number
  Ex: Let us take 36,36 is evenly divisible by 2,3,4,6....so these are the factors of 36

Factorization

Factorization is the representation of given number as the product of its factors
   Ex: Consider same example 36 for which 4*9 is the factorization of 36

Prime Factorization

A prime factorization of a number is the representation of that number as the product of its prime factors
   Ex:Prime factorization of 36 is  '2 *  2  *  3 *  3'

Program to get Prime Factorization of a Number

#include < stdio.h >
  void main() {
    int num, temp, i;
    printf("Enter Number:\n");
    scanf("%d", & num);
    temp = num;
    printf("Prime factorization for %d is\n\n", num);
    while (temp > 1) {
      for (i = 2; i <= temp; i++) {
        if (temp % i == 0) {
          printf("%d   ", i);
          temp /= i;
          break;
        }
      }
    }
  }

Output

Output for Prime Factorization



Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment