feat: solve 5-1

This commit is contained in:
Flinner Yuu 2022-07-18 07:48:41 +03:00
parent bfecc0b4ce
commit 428a0b4287
Signed by: flinner
GPG Key ID: 95CE0DA7F0E58CA6
1 changed files with 37 additions and 0 deletions

37
chapter-5/5-1.c Normal file
View File

@ -0,0 +1,37 @@
#include <ctype.h>
#include <stdio.h>
#define SIZE 100
int getint(int *pn) {
int c, sign;
while (isspace(c = getchar())) /* Ignore whitespace*/
;
if (c != '+' && c != '-' && !isdigit(c) && c != EOF) {
ungetc(c, stdin);
return 0;
}
sign = (c == '-') ? -1 : 1;
if (c == '+' || c == '-') {
c = getchar();
if (!isdigit(c)) {
ungetc(c, stdin);
return c;
}
}
for (*pn = 0; isdigit(c); c = getchar())
*pn = 10 * *pn + (c - '0');
*pn *= sign;
if (c != EOF)
ungetc(c, stdin);
return c;
}
int main() {
int n;
double array[SIZE];
for (n = 0; n < SIZE && getfloat(&array[n]) != EOF; n++)
;
}