- 1

Write a code using do while loop to read the numbers until -1 and also count the +ve, -ve & 0's encountered by the users

In C programming correct me #include<stdio.h> int main() { int n,p=0,ne=0,z=0; printf("Enter your number:%d"); do { scanf("%d",&n); if(n>0) p++; else if(n<0) ne++; else(n=0) z++; } while(n==-1); return 0; }

14th Apr 2020, 3:12 PM
Shaik Vajida
Shaik Vajida - avatar
2 Answers
+ 1
else if(n==0) z++; [else (n=0) is assigning, not comparing..and put ; at end if you are assigning like else n=0; ] n=0 assigning.. n==0 is comparing... After after while exit, print the calculated results,.. Before return statement...
14th Apr 2020, 4:46 PM
Jayakrishna 🇼🇳
+ 1
Sk Kaleshavali else n=0 It will give you an error.bcoz In else statement we need not to put any conditions.That's why if all the conditions are false then only your else statement excuted. (Sorry for bad English)
14th Apr 2020, 4:55 PM
Ramya Thiurmalisamy
Ramya Thiurmalisamy - avatar