30 likes | 374 Views
Example: Given long X[100]={ …}; Write a code segment to count the number of values below average in X. int I, sum, count; double avg; for( I=0, sum=0; I <=99; I++ ) sum+=X[I]; avg=sum/100.0; for( I=0, count=0; I <=99; I++ ) if (X[I]<avg) count++; printf(“%i”, count);.
E N D
Example: Given long X[100]={ …};Write a code segment to count the number of values below average in X. int I, sum, count; double avg; for( I=0, sum=0; I <=99; I++ ) sum+=X[I]; avg=sum/100.0; for( I=0, count=0; I <=99; I++ ) if (X[I]<avg) count++; printf(“%i”, count);
Example: Given long X[100]={ …}; long Y[100]={ …};Write a code segment to test if X=Y. int I; for( I=0; I <=99 && X[I]==Y[I]; I++ ); if (I==100) printf(“equal”); else printf(“not equal”);
Example: Write a program to convert from decimal into binary #include <stdio.h> void main( ){ int num, I, count, A[1000]; scanf(“%i”, &num); for (count=0; num ; num/=2) { A[count]=num%2; count++; }; for(I=count-1; I>=0; I--) printf(“%i”,A[I]); }