C语言自学路之计算平方(输入验证)
包含知识点:stdbool.h使用、自定义函数、多文件
检查用户输入是否是个整数,若不符合打印出并给予提示
若scanf()没有成功读取,就会将其留在输入队列中。这时候可以用getchar ( ) 函数逐字读取输入。
main.c 文件
/* 计算特定范围内所有整数平方和(-100^2 - 100^2)*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define MAX 100
#define MIN -100
long get_long(void);
bool text_limite(long putdown,long putup,long down,long up);
long sum_squares(long a ,long b);
int main()
{
long start,stop;//最大值与最小值
long answer;
printf("This program computes the sum of the squares of integers in a range.\n");
printf("The lower bound should not be less than -100.\n