Ask coding questions

← Back to all posts
Write a program to enter the numbers till the user wants and at the end (rest in discription)
SnehPratik (0)

Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered.

I'm a beginner and trying this from an hour.
please help me out, so that i can get over this.

Comments
hotnewtop
kbadrinath_tcsp (222)

i dont even know c, but by general knowledge i think you should do something like this (i' learning this syntax on a whim, so there might be some error, but you should get the general idea:
int neg;
int pos;
int zero;
int count;
printf("Enter your numbers: ");
scanf("%d", count);
count.split("")
//for this above statement, i have no idea how to split in c. Turning this into an array would be good, if you know how. this is assuming the user enters like this 1 3 4 5
for (i = 0; i < count.length; ++i) {
if (count[i]<=-1) {
neg++;
}
else if(count[i]==0) {
zero++;
}
else{
pos++;
}
printf("Positive numbers: " + pos "."+"Negative numbers: " + neg "."+"Zeroes: " + zero "."
}
again, this is my general idea of how you would do this in java or python, i just implemented it in c. I don't know if c is this flexible, but fix the syntax if you see anything wrong. Your c knowledge is probably better than mine.

SnehPratik (0)

@kbadrinath_tcsp

this is how i wrote the programm ,and it gets compiled too, but later after giving the user input, the system is behaving like nothing left to do.
help!!!!!

kbadrinath_tcsp (222)

you can't do while(a>0)! that will just give an infinite while lopp that will never end. you have to do a for loop i think, i dont think while loop will work here, especially how you used it. the for loop i used in my explanation up there should replace your while loop. @SnehPratik