Thursday, July 9, 2009

C programming?

how can u write a c program for the following:


Accept 10 nos. from user %26amp; print no. of +ve, -ve %26amp; zero's from that 10 nos. using if, for, while conditions. for printing the 10 nos. the compiler should ask the user 10 times to print any 10 nos.

C programming?
int numbers[10];


int nneg = 0;


int npos = 0;


int nzeros = 0;


int c = 0;


int i;





for(i =0 ;i %26lt; 10; i++)


{


cout%26lt;%26lt;"Enter the "%26lt;%26lt;i+1%26lt;%26lt;" number: ";


cin%26gt;%26gt;numbers[i];


cout%26lt;%26lt;"\n";


}





for(i = 0 ; i%26lt; 10 ; i++)


{


if(numbers[i] == 0)


nzeros++;


else if(numbers[i] %26gt; 0)


npos++;


else


nneg++:


}





cout%26lt;%26lt;"Number of positive numbers = "%26lt;%26lt;npos;


cout%26lt;%26lt;"Number of negative numbers = "%26lt;%26lt;nneg;


cout%26lt;%26lt;"Zero number = "%26lt;%26lt;nzeros;





i=0;


while(c == 0 %26amp;%26amp; i%26lt;10)


{


cout%26lt;%26lt;numbers[i];


i++;





cout%26lt;%26lt;"Do you want to display another number? o -%26gt; Yes 1 -%26gt; No";


cin%26gt;%26gt;c;


}


No comments:

Post a Comment