在哪里放置强数声明

在哪里放置强数声明

我已经制作了这个程序来计算数字分解,例如60 = 2^2 * 5 * 3
如何在不使用math.h库且不使用数组的情况下修改代码以打印9000 = 2^3 * 3^2 * 5^3之类的POWERFUL NUMBERS
非常感谢你!!

#include<stdio.h>
#define MAX 1000

int main(){
    int num;

    int counter;
    int number;
    char factorizationOutput;
    int isAchiles = 0;

    int factor=2;
        for(counter=2;counter<=MAX;counter++){
            isAchiles = 1;
            number=counter;
            int factor=2;

            while(factor<number){

                int power=0;

                if(number%factor==0){

                    while(number%factor==0){
                        number=number/factor;
                        power++;

                    }
                    if(power == 1){
                        isAchiles = 0;
                    }
                    printf("%d^%d",factor,power);
                    if(number!=1)
                        printf(" X ");

                }
                factor++;
            }
            if(number!=1)
                printf("%d^1.\n",factor);

            if(isAchiles == 1){
                printf("factorazation of number %d is: ",counter);

            }



}

}

最佳答案

#include<stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    printf("%d = ", n);
    for(int i = 1; i <= n; i++)
    {
        int count = 0;
        for(int j = 1; j <= i; j++)
        {
            if(i % j == 0)
            {
                count++;
            }
        }
        int l = 0;
        if(count == 2)
        {
            while(n % i == 0)
            {
                l++;
                n = n/i;
            }
            printf("%d^%d*", i, l);
        }
    }
}

关于c - 在哪里放置强数声明?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59092037/

10-09 08:45