C language programming exercises-decomposition of quality factors (debug),-debug

Source: Internet
Author: User

C language programming exercises-decomposition of quality factors (debug),-debug
Subject content:

Each non-prime number can be written into the form of multiplication of several prime numbers (also called prime numbers). These prime numbers are called the prime factor of the Union. For example, 6 can be divided into 2x3, while 24 can be divided into 2x2x2x3.

Now, your program needs to read an integer in the range of [2,], and then output its prime factor factorization formula. When it reads a prime number, It outputs itself.

 Input Format:An integer in the range of [2.

Output Format:For example, n = axbxcxd 2. n = n. There is no space between all symbols, and x is a lowercase letter x.

Input example:18

Output example:18 = 2x3x3

Time Limit: Ms memory limit: KB
1/* 2 subject content: 3 1. each non-prime number can be written into the form of multiplication of several prime numbers (also known as prime numbers); 4 2. these prime numbers are called the prime factor of the Union. For example, 6 can be divided into 2x3, while 24 can be divided into 2x2x2x3. 5 3. Enter an integer in the range of [2,], and then output its prime factor factorization formula. When it reads a prime number, It outputs itself. 4. Input Format: an integer in the range of [2. 7. Output Format: for example, n = axbxcxd or n = n. There is no space between all symbols, and x is a lowercase letter x. 8 6. input example: 18 9 7. output example: 18 = 2x3x3 10 11 4 = 2x212 6 = 2x313 8 = 2x2x214 915 1216 1417 1518 1619 */22 23 24 # include <stdio. h> 25 # include <math. h> 26 27 int isPrime (int a); 28 int rsUnprime (int a, int B); 29 30 int main () 31 {32 int num; 33 int pm = 2; 34 35 scanf ("% d", & num); 36 if (isPrime (num )! = 0) 37 {38 printf ("% d = % d", num, num); 39} else {40 printf ("% d =", num ); 41 while (num! = 1) {42 pm = rsUnprime (num, pm); 43 num = num/pm; 44 if (num! = 1) {45 printf ("% dx", pm); 46 47} else {48 printf ("% d", pm ); 49} 50} 51 // printf ("% d \ n", num); 52} 53 // return 0; 54} 55 56 57 int isPrime (int) 58 {59 int I; 60 int isPrime; 61 62 for (I = 2; I <a; I ++) 63 {64 if (a % I = 0) 65 {66 isPrime = 0; 67 break; 68} else {69 isPrime = 1; 70} 71} 72 return isPrime; 73} 74 75 int rsUnprime (int a, int B) 76 {77 int I = B; 78 79 while (a % I! = 0) {80 I ++; 81} 82 83 return I; 84}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.