bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc031.c (1678B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a program to enter numbers till the user wants. At the end it
      8 should display the count of positive, negative and zeros entered. */
      9 /* Let Us C, Chap- 5, Page - 87, Qn No.: B(d) */
     10 
     11 #include <stdio.h>
     12 int main()
     13 {
     14     int choice = 1, num, positive_count = 0, negative_count = 0, zero_count = 0;
     15     while (choice == 1)
     16     {
     17         printf("\nEnter the number (Type any character and press Enter to finish.) : ");
     18         choice = scanf("%d", &num); // Checking whether the user has input any characters
     19         if (choice == 1)
     20         {
     21             printf("Number recorded : %d", num);
     22             if (num < 0)
     23                 negative_count++;
     24             else if (num > 0)
     25                 positive_count++;
     26             else if (num == 0)
     27                 zero_count++;
     28         }
     29         else 
     30         {
     31         // If the user inputs any characters, then choice = 0, it means he doesn't want to give any more input;
     32             choice = 0;
     33             printf("\nCharacter received. Stopping input...\n");
     34         }
     35     }
     36     // Display the final results
     37     printf("\n====================================\n");
     38     printf("   Analysis Complete\n");
     39     printf("====================================\n");
     40     printf("Positive numbers entered: %d\n", positive_count);
     41     printf("Negative numbers entered: %d\n", negative_count);
     42     printf("Zeroes entered:           %d\n", zero_count);
     43     printf("Total numbers recorded:   %d\n", positive_count + negative_count + zero_count);
     44     printf("====================================\n");
     45 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror