Question: Can you help me fix this problem, it isn't working as it should. #include /* This program calculates the number of digits in a number
Can you help me fix this problem, it isn't working as it should.
#include
/* This program calculates the number of digits in a number from 1 to 100000*/
void digits(int n);
int main() { int input;
printf("Please input a number from 1 up to 10000000: ");
scanf("%d", &input);
if( input > 10000000 || input < 1) { printf("Invalid number! "); return -1; }
digits(input);
return 0; }
/* This function divides a number by the 10^n, to see if the divided number * has "n" digits */ void digits(int n) { if((double)n/10000000!=0) { printf("8 digits "); } else if((double)n/1000000!=0) { printf("7 digits "); } else if((double)n/100000!=0) { printf("6 digits "); } else if ((double)n/10000!=0) { printf("5 digits "); } else if ((double)n/1000!=0) { printf("4 digits "); } else if ((double)n/100!=0) { printf("3 digits "); } else if ((double)n/10!=0) { printf("2 digits "); } else if ((double)n/1!=0) { printf("1 digit "); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
