Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* count characters in input; 1st version */
- main()
- {
- long nc;
- nc = 0;
- while (getchar() != EOF)
- ++nc;
- printf("%ldn", nc);
- }
- #include <stdio.h>
- /* count characters in input; 2nd version */
- main()
- {
- double nc;
- for (nc = 0; getchar() != EOF; ++nc)
- ;
- printf("%.0fn", nc);
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <float.h>
- /* count characters in input; SO version */
- int main(void)
- {
- double total;
- float batch; /* change me to double */
- for (total = 0.0, batch = 0.0; getchar() != EOF; ) {
- float batch_new = batch + 1.0; /* me too */
- if (batch_new - batch != 1.0) {
- total += batch;
- batch = 1.0;
- } else {
- batch = batch_new;
- }
- }
- if (ferror(stdin)) {
- printf("I/O error on standard inputn");
- return EXIT_FAILURE;
- }
- if (total == 0.0)
- printf("%.0f (exact)n", batch);
- else
- printf("%.*g (approx)n", DBL_DIG, total + batch);
- return 0;
- }
- double
Add Comment
Please, Sign In to add comment