Select the missing code lines from the dropdown provided.The C code given below should count digits of a number entered by the user.But, line numbers 7 and 9 are missing.1. #include <stdio.h>2. int main()3. {4. int num,count=0;5. printf("Enter an integer: ");6. scanf("%d", &num);7. ---------------Missing code -------------------8. {9. ---------------Missing code -------------------10. ++count;11. }12. printf("Number of digits: %d",count);13. }
Question
Select the missing code lines from the dropdown provided.The C code given below should count digits of a number entered by the user.But, line numbers 7 and 9 are missing.1. #include <stdio.h>2. int main()3. {4. int num,count=0;5. printf("Enter an integer: ");6. scanf("%d", &num);7. ---------------Missing code -------------------8. {9. ---------------Missing code -------------------10. ++count;11. }12. printf("Number of digits: %d",count);13. }
Solution
The missing code lines are for a while loop that will continue as long as the number is not zero. In each iteration of the loop, the number is divided by 10, effectively removing the last digit. This is how the code counts the number of digits. Here are the missing lines:
- while(num != 0)
- num = num / 10;
So the complete code would be:
- #include <stdio.h>
- int main()
- {
- int num,count=0;
- printf("Enter an integer: ");
- scanf("%d", &num);
- while(num != 0)
- {
- num = num / 10;
-
++count; - }
- printf("Number of digits: %d",count);
- }
Similar Questions
Select the missing code lines from the dropdown provided.The C code given below should print the sum of digits of a number entered by the user.But, line numbers 6 and 10 are missing.1. #include<stdio.h>2. int main()3. {4. int num, sum=0, rem;5. printf("Enter a number\n");6. ---------------Missing code -------------------7. while(num>0)8. {9. rem = num%10;10. ---------------Missing code ------------------- 11. num = num/10;12. }13. printf("Sum is %d\n", sum);14. return 0;15. }
Select the missing code lines from the dropdown provided.The C code given below should find the product of two numbers entered by the user.But, line numbers 4 and 7 are missing.#include<stdio.h>int main(){ ---------------Missing code ------------------- printf("Enter two numbers\n"); scanf("%d%d",&a,&b); ---------------Missing code ------------------- return 0;}
Select the missing code lines from the dropdown provided.The C code given below should print the factorial of a number entered by the user.But, line numbers 4 and 10 are missing.1. #include<stdio.h>2. int main()3. {4. ---------------Missing code -------------------5. printf("Enter a number\n");6. scanf("%d",&num);7. while(num>0)8. {9. fact = fact * num;10. ---------------Missing code -------------------11. }12. printf("Factorial is %d\n", fact);13. return 0;14. }
Select the missing code lines from the dropdown provided.The C code given below should print the reverse of a number entered by the user.But, line numbers 9 and 10 are missing.1. #include <stdio.h>2. int main()3. {4. int num, reverse=0, rem;5. printf("Enter an integer:");6. scanf("%d", &num);7. while(num>0)8. {9. ---------------Missing code -------------------10. ---------------Missing code -------------------11. num/=10;12. }13. printf("Reverse is = %d",reverse);14. return 0;15. }
Write a C program to count number of digits in a number. Using do-while loop
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.