小编Bal*_*ran的帖子

输入两个数字的值

实际上,我正在学习C语言,并且编写了一个程序

输入2个数字的值,如下所示。

#include<stdio.h>
int main()
{
    int a, b, c;
    printf("Enter two numbers to add\n");
    scanf("%d%d", &a, &b);
    printf("Sum of the numbers = %d\n", c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我输入一个字母,我会得到一些1522222数字。取而代之的是,如果我输入字母(即a,b,c),它会抛出错误作为无效输入。

我该怎么办?

c input scanf

0
推荐指数
1
解决办法
73
查看次数

标签 统计

c ×1

input ×1

scanf ×1