gpt4 book ai didi

c - 在哪里放置强大数字的声明?

转载 作者:行者123 更新时间:2023-11-30 16:09:39 28 4
gpt4 key购买 nike

我编写了这个程序来计算数字分解,例如60 = 2^2 * 5 * 3。我如何修改我的代码以打印 POWERFUL NUMBERS例如 9000 = 2^3 * 3^2 * 5^3 不使用 math.h 库且不使用数组?非常感谢!!

#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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com