In this I will tell you how to write a program in which we can count number of zeros, number of positive integers , number of negative integers . So without any further delay let's get started . First I will show you code then we come to explanation.
Code:
Logic :
The logic here is very simple . Here we first three integer n1 , n2 , n3 and initialize it from zero .Then we open a for loop and start it from 0 and till 10 . You can also do it without other loops. And then we use if condition for zero if true then value of n1++(increase by one ). Then we come to next condition of else if for positive integers if true then n2++(increase by one). Then we come to negative integers if true then n3++(increase by one ). And in end we use printf and print number of zeros ,then positive integers and then negative integers .
Output:
You can see as we run loop till 10 that why here we have 1 zero , 10 positive integers because we start from 0 . No negative integers you must try this on your pc . And you can also run this loop till user given number by changing condition of loop .
I hope that you find this helpful in your work .
Thanks for reading .
No comments:
Post a Comment