Created
September 1, 2021 05:30
-
-
Save avii-7/3840b55c1d505b2f865ba384678b90cc to your computer and use it in GitHub Desktop.
90. Twenty-five number are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are odd and how many are even.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void getData(int *, int *, int); | |
int main() | |
{ | |
int arr[] = {11, 44, -2, 351, -1129, 34, 3, -124, 25, -9}; | |
int size = sizeof(arr) / sizeof(arr[0]); | |
int count[4]; | |
getData(arr, count, size); | |
printf("Positive Numbers: %d", *(count)); | |
printf("\nNegative Numbers: %d", *(count + 1)); | |
printf("\nEven Numbers: %d", *(count + 2)); | |
printf("\nOdd Numbers: %d", *(count + 3)); | |
return 0; | |
} | |
void getData(int *arr, int *count, int n) | |
{ | |
int w, x, y, z; | |
w = x = y = z = 0; | |
for (int i = 0; i < n; i++) | |
{ | |
//Positive and Negative | |
if (*(arr + i) > 0) | |
*(count) = ++w; | |
else | |
*(count + 1) = ++x; | |
// Odd and Even | |
if (*(arr + i) % 2) | |
*(count + 3) = ++z; | |
else | |
*(count + 2) = ++y; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment