c - 为什么下面的 C 代码不起作用?我无法找出错误。

标签 c arrays memory-management memory-leaks

不知道问题出在哪里。代码编译时没有任何错误,但在运行时,它要求我输入一个数字,但当我在给出输入后按回车键时,它崩溃了。谁能告诉我问题出在哪里?我认为存在一些内存问题,但我不知道在哪里。提前致谢。

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

int main(void)
{ 
    int n[16];
    long long a;
    printf("enter your credit card number \n");
    scanf(" %lld", &a);
    int i;
    for ( i = 0; i < 15; i++)
    {
        n[i] = (a % (10^(15-i))) / 10^(14-i);
    }
    int m = (n[1] + n[3] + n[5] + n[7] + n[9] + n[11] + n[13]);
int w = 2 * m;
int k = w % 10;
int l = n[0] + n[2] + n[4] + n[6] + n[8] + n[10] + n[12] + n[14];
int z = k + l;
if (z % 10 == 0)
{
    printf("you card is valid");
}
else
{
    printf("go get a new card");
}
return 0;
}

最佳答案

^ 表示按位异或。如果您想获得某物的力量,请使用 pow() 函数。

关于c - 为什么下面的 C 代码不起作用?我无法找出错误。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41263681/

相关文章:

c - sprintf 缩放整数。 123 打印为 12,3

php - 如何用php在URL中传递多维

c - 使用 Malloc (char & int) 分配内存

c++ - 删除数组时delete和delete[]是一样的吗?

Delphi 上的 C dll 头文件

c - 我什么时候使用扩展数据?

c++ - 在 C++ 中创建一个文件,就像按右键->新建->新建文本文档一样

arrays - 检查一个数组是否包含另一个数组的所有值(是否所有用户都分配了工作?)

javascript - node.removeChild(node.firstChild) 是否会造成内存泄漏?

c++ - 使用 c_str() 和 const char * 进行适当的内存清理