我正在尝试查找C中两个字母之间的距离(使用字符)

问题描述 投票:0回答:1

这是我能走的最远

#include <stdio.h>

int main()
{

    char a, b;
    int z, abs(inx);

    printf("Enter two English Alphabets: ");

    scanf("%d %d", &a, &b);

        if (abs(a-b) == 0)
            printf("\n.\n");
        else
            printf("\nPlease enter a English alphabet.\n");
        z=abs(a-b); 
        printf("\nThe distance between the characters is  = %d",z);
        return 0;
    }

但它总是返回0

而且我假设ascii值是自动存储的,但是我不知道发生了什么。

c
1个回答
0
投票
scanf("%d %d", &a, &b);

如下更改此语句。

scanf("%c %c", &a, &b);

让我知道是否可行。

© www.soinside.com 2019 - 2024. All rights reserved.