decomposes a positive integer decomposition

Source: Internet
Author: User
Tags printf

See the full set of "C language problem sets"

Topic:

Decomposes a positive integer into decomposition. For example: Enter 90, print out 90=2*3*3*5.

Program analysis: N to decompose decomposition, you should find a minimum prime number k, and then complete the following steps:

(1) If this prime number is equal to n, then the process of decomposing decomposition is finished and printed out.

(2) if n<>k, but n can be divided by K, you should print out the value of K, and n divided by the quotient of K, as a new positive integer you n, repeat the first step.

(3) If n cannot be divisible by K, then repeat the first step using k+1 as the value of K.

2. Program Source code:

#include "stdio.h"
#include "conio.h"
Main ()
{
int n,i;
printf ("\nplease input a number:\n");
scanf ("%d", &n);
printf ("%d=", N);
for (i=2;i<=n;i++)
while (n!=i)
{
if (n%i==0)
{
printf ("%d*", I);
n=n/i;
}
Else
Break
}
printf ("%d", n);
Getch ();
}

3.Visual C + + 6.0 debugging pass, as shown in figure:

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.