Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m trying to write the function definitions for getting the smallest & largest

ID: 3530591 • Letter: I

Question

I'm trying to write the function definitions for getting the smallest & largest digit of a number entered by the user. But I keep getting the answer as "1" ( at least for the smaller) , no matter what numbers I key into the program. Please tell me what I'm getting wrong. ================================================================================================= #include #include // Function declarations int countDigits(num); int getSum(int); int getAverage(int); int getSmallest(num); int getLargest(int); int main(){ // Local declarations int num,count, sum, average, smallest, largest; printf("Enter numbers with (99999 to stop): "); scanf("%d",&num); count=countDigits(num); printf("The number of integers is: %d ",count); sum=getSum(num); printf("The sum of the integers is: %d ",sum); average=getAverage(num); printf("The average of the integers is: %d ",average); smallest=getSmallest(num); printf("The smallest integer is: %d ", smallest); largest=getLargest(num); printf("The largest integer is: %d ",largest); system("PAUSE"); return 0; } // main // ===== countDigits ===== int countDigits(int num){ static int count=0; if(num!=0){ count++; countDigits(num/10); } return count; }//countDigits // ===== getSum ===== int getSum(int num){ static int sum=0,x; if(num!=0){ x=num; sum=sum+x; getSum(num/10); } return sum; }//getSum // ===== getAverage ===== int getAverage(int avg){ int n, count; float sum=0, x; for(count = 1; count<=n; count++){ sum+=x; } avg=sum/n; return avg; }//getAverage // ===== getLargest ===== int getLargest(int num){ int x, last, tmp; if (x<10) return x; last= x/10; tmp= getLargest (x/10); if (last>tmp) tmp= last; return tmp; }//getLarger // ===== getSmallest ===== int getSmallest(num){ //Local Definitions int x, n, i, d[10], k, s; //Statements for(i=0,x=n;x>0;i++){ d[i]=x; x=x/10; } k=i; s=d[0]; for(i=1;i

Explanation / Answer

ques incomplete