P. 1
C and C++ in 5 days

C and C++ in 5 days

|Views: 184|Likes:
Published by xinuxnet
learn C and C++ in five days
learn C and C++ in five days

More info:

Published by: xinuxnet on Jan 19, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Given the partially written program below, fix the indicated bug, and add
code to count the number of negative, zero and positive numbers in the
data read in. You should use switch, if and at least one loop construct


/* bug: should check if s is zero */
int sign (int s)

return abs(s)/s;


main ()

int data [10],
i, n,
negatives, zeros, positives;
n = sizeof data / sizeof (int);
negatives = zeros = positives = 0;
printf("Enter %d numbers : ", n);
/* need loop on i from 0 to n-1 around this */

/* read in the data */
scanf("%d", &data[i]);
/* now count negatives , zeros, positives */

negatives, zeros, positives);



You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->