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. }
Question
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. }
Solution
The missing code lines are:
- int num, fact = 1;
- num--;
So, the complete code will be:
- #include<stdio.h>
- int main()
- {
- int num, fact = 1;
- printf("Enter a number\n");
- scanf("%d",&num);
- while(num>0)
- {
- fact = fact * num;
- num--;
- }
- printf("Factorial is %d\n", fact);
- return 0;
- }
Similar Questions
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 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 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. }
Factorial NumberYou are given a Python code snippet that aims to calculate the factorial of a given number. However, some parts of the code are missing. Fill in the missing code to complete the program.Sample Test CasesTest Case 1:Expected Output:Enter·a·number:·3The·factorial·of·3·is:·6Test Case 2:Expected Output:Enter·a·number:·4The·factorial·of·4·is:·24Submit12345678910111213141516#·Fill·in·the·missing·code·below·to·calculate·the·factorial·of·a·number¬¬#·Prompt·the·user·to·enter·a·number¬number·=·int(input("Enter·a·number:·"))¬¬#·Initialize·the·factorial·variable¬factorial·=·¬¬#·Fill·in·the·missing·code·to·calculate·the·factorial·of·the·number¬for·i·in·range(·····):¬····¬····factorial·=·¬¬#·Display·the·calculated·factorial¬print("The·factorial·of",·number,·"is:",········)¬¶
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.