使用_bool变量

#include stdio.h#include stdbool.hint main(void){long num;long sum = 0L;bool input_is_good;

编程学习网为您整理以下代码实例,主要实现:使用_bool变量,希望可以帮到各位朋友。

#include <stdio.h>
#include <stdbool.h>

int main(voID){
    long num;
    long sum = 0L;
    bool input_is_good;

    printf("Please enter an integer to be summed ");
    printf("(q to quit): ");
    input_is_good = (scanf("%ld", &num) == 1);

    while (input_is_good){
        sum = sum + num;
        printf("Please enter next integer (q to quit): ");
        input_is_good = (scanf("%ld", &num) == 1);
    }
    printf("sum: %ld.\n", sum);

    return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐