gpt4 book ai didi

c - 在 C 中扫描 long long int 时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:56:52 25 4
gpt4 key购买 nike

<分区>

我正在尝试编写一个简单的程序来计算两个数字的公因子数。我遇到了在扫描第二个数字时发生的段错误(核心转储)。我不明白错误在哪里?

#include <stdio.h>
#include <stdlib.h>

int main()
{
long long int first,second,t,k;
long long int i,count=0;
scanf("%lld",&first);
scanf("%lld",&second);
//storing the lowest of two numbers in t
if(first<second){
t=first;
}
else{
t=second;
}
//initialising an array to be used as flags
int com[t];
for(i=0;i<t;i=i+1){
com[i]=1;
}
for(i=0;i<t;i=i+1){
if(com[i]==1){
if(first%(i+1)==0&&second%(i+1)==0){
count=count+1;
}
else{
for(k=2;k*(i+1)-1<t;k=k+1){
com[k*(i+1)-1]=0;
}
}
}
}
printf("%lld\n",count);
return 0;
}

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