Skip to content

Instantly share code, notes, and snippets.

@btechmag
Last active April 29, 2021 08:49
Show Gist options
  • Save btechmag/e09baf3e5fe0cdc66b657a0dfd4e12dd to your computer and use it in GitHub Desktop.
Save btechmag/e09baf3e5fe0cdc66b657a0dfd4e12dd to your computer and use it in GitHub Desktop.
C Program that reads 5 numbers and counts the number of positive and negative numbers.
#include<stdio.h>
int main()
{
//Program that reads 5 numbers and counts the number of positive and negative numbers
int n[5];
int i,pos = 0,neg = 0;
for(i = 0; i < 5; i++)
{
printf("Input the elements n[%d] : ", i);
scanf("%d", &n[i]);
{
if(n[i] > 0)
{
pos++;
}
else if(n[i] < 0)
{
neg++;
}
}
}
printf("Number of positive numbers: %d\n" ,pos);
printf("Number of negative numbers: %d" ,neg);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment