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. }
Question
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. }
Solution
The missing code lines are:
Line 6: scanf("%d", &num); This line is used to take the input from the user. The "%d" format specifier is used to take an integer as input. The "&" operator is used to get the address of the variable 'num'.
Line 10: sum = sum + rem; This line is used to add the remainder 'rem' to the 'sum'. The remainder 'rem' is the last digit of the number 'num' and we add this to the 'sum' to get the sum of all digits.
Similar Questions
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. }
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. }
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 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;}
#include<stdio.h> int main(){ int number,sum=0,digit; printf("Enter an integer : "); scanf("%d",&number); while (number != 0){ digit=number%10; sum += digit; number /= 10 } printf("The sum of digits of the given number "%d" = %d",number,sum); return 0; }
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.