In this tutorial you will learn about the C Program to Count Positive Negative Zero and its application with practical example.
C Program to Count Positive Negative Zero
In this tutorial, we will learn to create a C program that will Count Positive Negative Zero using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C Programming.
- While Loop in C programming.
- Conditional Statements in C programming.
Program to Count Positive Negative Zero
In c programming, it is possible to take numerical input from the user and Count Positive Negative Zero from the given number with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them. With the help of these functions, the programming is easy.
With the help of this program, we can Count Positive Negative Zero.
Here,
We will first take the input
The second will make Count Positive Negative Zero.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variables for the program. 2. Taking the input size of number from the user. 3. Taking the elements from the user. 4. Calculating the positive, negative, zeroes from the numbers. 5. Printing the result number. 6. End Program. |
Program to Count Positive Negative Zero:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include <stdio.h> int main() { //declaring the variable for the program int size, no, positive = 0, negative = 0, zero = 0; //Taking input size from the user printf("Enter the number of elements :- \n"); scanf("%d", &size); //Taking input from the elements from the user printf("Enter %d numbers\n", size); //Calculating the positive, negative, zeroes while(size) { scanf("%d", &no); if(no > 0) { positive++; } else if(no < 0) { negative++; } else { zero++; } size--; } //Printing output numbers printf("\nPositive Numbers: %d\n", positive); printf("Negative Numbers: %d\n", negative); printf("Number of zero: %d\n", zero); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- size = it will hold the integer value.
- no = it will hold the integer value.
- positive = it will hold the integer value.
- negative = it will hold the integer value.
- zero = it will hold the integer value.
Input number from the user.
Program Logic Code.
Printing the output.