Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C中创建一个空数组来存储从给定from程序计算出的值_C_Arrays_Multidimensional Array - Fatal编程技术网

如何在C中创建一个空数组来存储从给定from程序计算出的值

如何在C中创建一个空数组来存储从给定from程序计算出的值,c,arrays,multidimensional-array,C,Arrays,Multidimensional Array,我在初始化一个数组时遇到了困难,无法确定for循环中的值是如何给出的。我想放弃计算出的素数,然后将非素数保留在一个数组中,数组的大小从一开始就必须是未知的。然后我必须调用收集数组中的数字,然后对它们应用Carmichael方程来找到Carmichael数字 我发现将方程应用于数组中的值也是困难的。 这是我的代码: int main(int argc, char **argv){ int a ,b; int notPrime[] = {}; printf("Type in

我在初始化一个数组时遇到了困难,无法确定for循环中的值是如何给出的。我想放弃计算出的素数,然后将非素数保留在一个数组中,数组的大小从一开始就必须是未知的。然后我必须调用收集数组中的数字,然后对它们应用Carmichael方程来找到Carmichael数字

我发现将方程应用于数组中的值也是困难的。 这是我的代码:

int main(int argc, char **argv){
    int a ,b;
    int notPrime[] = {};
    printf("Type in two non negative intergers: \n");
    scanf("%d" "%d", &a , &b);
    int i=a , k=0 ,count=0, j, p, m;
    for (i < b;){    //from the integers given b must be the larger of the two 
        if (i==0 || i==1) {  //to calculte the prime numbers
            notPrime[k]=i;
        }else{
            for( j=2;j<i;j++){
                if(i%j==0){
                    break;
                }else{
                    notPrime[k]=i;
                }
            }
        }
        i++;
        k++;
    }
    p=0;
    if (p<=k){
        for (m=1;m<notPrime[p];m++){
            if((pow(m,notPrime[p])-m)%notPrime[p]==0){ //use of the values in the array and use of the carmichael equation
                count=count+1;
            }
            if(count==notPrime[p]-1){
                Printf( "%d \n", &notPrime[p]) ;
            }
        }
    }
    return 0;
}
我有错误,因为我 请给我一点帮助,让我朝着正确的方向走,我会努力改正的

狂喜

for (i < b;){    
还有这个-

if((pow(m,notPrime[p])-m)%notPrime[p]==0){ //
pow返回double和notPrime[p]为int。%n运算符位于double和int上

将pow的结果显式强制转换为int

还有这个-

 printf( "%d \n", &notPrime[p]) ;
                  ^ this is not needed 
不要传递int的地址

编辑- 在获取输入a和b后,可以将数组声明为-


因为i printf( "%d \n", &notPrime[p]) ; ^ this is not needed
 int notPrime[a] = {0};           // or size b as you desire