C program to count numbers of positive and negative numbers
Write a C program using arrays to count the numbers of positive and negative numbers which accepts the inputs as "size of the array" & "elements of the array" and outputs as "number of negative numbers in an array are" & "numbers of positive numbers in an array are" ?
RE: C program to count numbers of positive and negativ...
#include <stdio.h> int main() { int p_nArr[20] {0}; int nCount_Pos 0; int nCount_Neg 0; int num 0; int SIZEOFARRAY 0; int index; printf("nEnter the Size of the array"); scanf(" d" &SIZEOFARRAY); printf("nEnter the elements ::n"); for( index 0; index < SIZEOFARRAY; index++ ) { scanf(" d" &p_nArr[index]); if (p_nArr[index] > 0 ) nCount_Pos++ ; else if (p_nArr[index] < 0 ) nCount_Neg++; } if ( nCount_Neg > 0) { printf("nNumber of negative numbers in the array are :: dn" nCount_Neg); for( index 0; index < SIZEOFARRAY; index++ ) { if (p_nArr[index] < 0 ) printf(" d " p_nArr[index]); } } if ( nCount_Pos > 0 ) { printf("nNumber of Positive numbers in the array are :: dn" nCount_Pos); for( index 0; index < SIZEOFARRAY; index++ ) { if (p_nArr[index] > 0 ) printf(" d " p_nArr[index]); } }
getch(); }
//Note : This program can be solved efficiently using linked list.
RE: C program to count numbers of positive and negative numbers
#include<conio.h> #include<stdio.h>
void main() { int *arr num i 0 pos 0 neg 0; clrscr(); printf("Enter The Number Of Elements :"); scanf(" d" &num); arr (int *)malloc(num*2); printf("Enter The Numbers :"); for(i 0;i<num;i++) { scanf(" d" arr+i); if(arr[i]>0) pos++; else neg++; } printf("The Number Of Positive Numbers Are : d" pos); printf("The Number Of Negative Numbers Are : d" neg); printf("Number Of Zeros Are : d" num-(pos+neg)); getch(); }