At Westonci.ca, we make it easy to get the answers you need from a community of informed and experienced contributors. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

Write a program to repeatedly read integers from the standard input until it reads "-1" and exits. For each number before "-1," if it is positive and odd, do the following:

Sagot :

anu20

Answer:

#include <stdio.h>  

int main() {  

int p=0, n=0, z=0, inp=0;  

printf("How do I write a C program to read numbers until -1 "  

 "is encountered and also count the number of positive, negative, "  

 "zeroes encountered by users using a while loop?\n\n\n");  

printf("Enter an integer  (-1 to quit): ");  

scanf("%d",&inp);  

while(inp != -1) {  

 if(inp > 0) p++;  

 else if(inp < 0) n++;  

 else z++;  

 printf("\nEnter next integer (-1 to quit): ");  

 scanf("%d",&inp);  

}  

n++; /* -1 is also a -ve number */  

printf("You have entered ...\n");  

printf("\t\tPositive numbers: %d\n",p);  

printf("\t\tNegative numbers: %d\n",n);  

printf("\t\t          Zeroes: %d\n",z);  

}

Explanation: